Skip to content

Phase 3, Task 11: Make NextJsNextDataRewriter fragment-safe #586

@aram356

Description

@aram356

Parent: #563

Summary

`NextJsNextDataRewriter` assumes it receives complete text node content in a single `rewrite()` call. Under the streaming `HtmlRewriterAdapter`, lol_html may split text nodes across chunk boundaries, causing silent missed rewrites on large `NEXT_DATA` payloads.

Changes

  • Accumulate text fragments in `NextJsNextDataRewriter` until `TextChunk::last_in_text_node()` is true
  • Only perform the rewrite on the complete accumulated text
  • Add regression test with small chunk size that splits a `NEXT_DATA` payload mid-string

File: `crates/trusted-server-core/src/integrations/nextjs/script_rewriter.rs`

Plan

See `docs/superpowers/specs/2026-03-25-streaming-response-design.md` — Phase 3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions