Skip to content

SSR streaming may emit malformed HTML when document closing tags span multiple chunks #87877

@vincent-turato

Description

@vincent-turato

Link to the code that reproduces this issue

https://github.com/vincent-turato/next.js

To Reproduce

  1. Clone the reproduction repository:
    git clone https://github.com/vincent-turato/next.js.git
    cd next.js

  2. Check out the reproduction branch:
    git checkout repro/streaming-html-suffix-bug

  3. Install dependencies:
    pnpm install

  4. Build the Next.js packages:
    pnpm build

  5. Run the failing test:
    pnpm test packages/next/src/server/stream-utils/node-web-streams-helper.test.ts

  6. Observe the failure showing incorrect handling when the closing HTML suffix spans multiple stream chunks:

    FAIL packages/next/src/server/stream-utils/node-web-streams-helper.test.ts
    createMoveSuffixStream
    ✕ duplicates closing tags when suffix spans chunks

    ● createMoveSuffixStream › duplicates closing tags when suffix spans
    Expected: "Hello"
    Received: "Hello"

Current vs. Expected behavior

Expected: "Hello"
Received: "Hello"

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #37~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 20 10:25:38 UTC 2
  Available memory (MB): 23956
  Available CPU cores: 16
Binaries:
  Node: 22.19.0
  npm: 10.9.3
  Yarn: N/A
  pnpm: 9.6.0
Relevant Packages:
  next: 16.1.1-canary.7 // Latest available version is detected (16.1.1-canary.7).
  eslint-config-next: N/A
  react: 19.3.0-canary-65eec428-20251218
  react-dom: 19.3.0-canary-65eec428-20251218
  typescript: 5.9.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Loading UI and Streaming

Which stage(s) are affected? (Select all that apply)

Vercel (Deployed)

Additional context

Potential impacts of this issue include:

  • Reliance on browser HTML error recovery during parsing, which can lead to subtle or undefined hydration behavior in SSR streaming paths (see https://nextjs.org/docs/messages/react-hydration-error).
  • Emission of malformed or incomplete HTML during server-side streaming when document closing tags span multiple chunks.
  • Missing </body> and/or </html> tags in the streamed response under specific chunking conditions that do not occur in fully buffered renders.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Loading UI and StreamingRelated to loading UI (loading.tsx) and streaming.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions