Skip to content

Make body hold parser-aware and stream Next.js processing - #1135

Draft
prk-Jr wants to merge 16 commits into
mainfrom
fix/850-parser-aware-body-hold-nextjs-streaming
Draft

Make body hold parser-aware and stream Next.js processing#1135
prk-Jr wants to merge 16 commits into
mainfrom
fix/850-parser-aware-body-hold-nextjs-streaming

Conversation

@prk-Jr

@prk-Jr prk-Jr commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Use a parser-generated, request-specific seam to delay only the structural </body> tail, preventing inline JavaScript or JSON literals from holding most of the page.
  • Replace whole-document Next.js post-processing with bounded per-document streaming that rewrites complete RSC groups and restores malformed, incomplete, or over-limit payloads unchanged.
  • Preserve auction ordering and terminal telemetry across streaming, compressed, missing-body-end, and failure paths.

Changes

File Change
crates/trusted-server-core/src/html_processor.rs Insert a parser-confirmed deferred body marker and stream transformed output.
crates/trusted-server-core/src/integrations/google_tag_manager.rs Adapt registration to the per-document processor interface.
crates/trusted-server-core/src/integrations/mod.rs Define the per-document HTML stream processor factory contract.
crates/trusted-server-core/src/integrations/nextjs/html_post_process.rs Remove the whole-document Next.js post-processor.
crates/trusted-server-core/src/integrations/nextjs/mod.rs Register the bounded Next.js stream processor.
crates/trusted-server-core/src/integrations/nextjs/rsc.rs Classify malformed and incomplete RSC T-chunks safely, including decoded character boundaries.
crates/trusted-server-core/src/integrations/nextjs/rsc_placeholders.rs Capture RSC scripts into request-namespaced placeholders with bounded fallback.
crates/trusted-server-core/src/integrations/nextjs/rsc_stream.rs Add ordered, bounded RSC grouping, rewriting, restoration, and streaming release.
crates/trusted-server-core/src/integrations/nextjs/script_rewriter.rs Move Next.js script fragment state to the document scope.
crates/trusted-server-core/src/integrations/nextjs/shared.rs Share URL rewrite support with the stream processor.
crates/trusted-server-core/src/integrations/registry.rs Construct processor instances per document.
crates/trusted-server-core/src/publisher.rs Collect auctions at the parser-confirmed seam while preserving early output and abandonment telemetry.
docs/guide/integrations/nextjs.md Document bounded Next.js streaming and unchanged fallback behavior.
docs/superpowers/specs/2026-09-07-850-parser-aware-body-hold-nextjs-streaming-design.md Add the reviewed design specification.
docs/superpowers/plans/2026-09-07-850-parser-aware-body-hold-nextjs-streaming.md Add the reviewed implementation plan.

Closes

Closes #850

Test plan

  • cargo test-fastly && cargo test-axum
  • cargo clippy-fastly && cargo clippy-axum
  • cargo fmt --all -- --check
  • JS tests: cd crates/trusted-server-js/lib && npx vitest run (blocked by the existing CommonJS/ESM incompatibility between html-encoding-sniffer and @exodus/bytes; no JS files changed)
  • JS format: cd crates/trusted-server-js/lib && npm run format
  • Docs format: cd docs && npm run format
  • WASM build: cargo build --package trusted-server-adapter-fastly --release --target wasm32-wasip1
  • Manual testing via fastly compute serve
  • Other: cargo test-cloudflare, cargo test-spin, cargo clippy-cloudflare, cargo clippy-cloudflare-wasm, cargo clippy-spin-native, and cargo clippy-spin-wasm

Checklist

  • Changes follow CLAUDE.md conventions
  • No unwrap() in production code — use expect("should ...")
  • Uses repository logging macros (not println!)
  • New code has tests
  • No secrets or credentials committed

@prk-Jr prk-Jr self-assigned this Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix </body> hold-buffer scan to use parser context; make nextjs post-processor streaming-safe

1 participant