Skip to content

Conversation

@VedantKh
Copy link

Fixes #34966

Summary

This PR fixes an issue where renderToPipeableStream with the onAllReady callback incorrectly injected streaming scripts and hidden HTML elements even when all content was fully loaded. This negatively impacted SEO scores for crawlers.

Changes

  • Modified flushSegment in ReactFizzServer.js to check allPendingTasks > 0 before outlining Suspense boundaries
  • Modified flushCompletedQueues in ReactFizzServer.js to skip blocking shell instructions when allPendingTasks === 0
  • Modified writeCompletedRoot in ReactFizzConfigDOM.js to only emit template tag when not complete
  • Updated test snapshots to reflect new behavior (no streaming instructions when using onAllReady)
  • Added new test file ReactDOMFizzServerNodeIssue34966-test.js to verify the fix

Test Plan

  • Added specific tests for the reported issue in ReactDOMFizzServerNodeIssue34966-test.js
  • Verified streaming still works correctly in onShellReady mode
  • All existing tests pass with updated snapshots

Before:

<div hidden id="S:0"><button>Test</button></div>
<script>$RB=[];$RV=function(a){...};</script>
<template id="_R_"></template>
<link rel="expect" href="#_R_" blocking="render"/>

After:

<!DOCTYPE html>
<html><head></head><body><button>Test</button></body></html>

Clean HTML with no streaming scripts, hidden elements, or template tags when using onAllReady.


Link to Devin run: https://app.devin.ai/sessions/7c96c346bafa4e9fb3db53359e2e9c30
Requested by: Vedant Khanna ([email protected]) (@VedantKh)
Analysis session: devin-f682e0bd30014103a2590bcb6e053cb4

…ng onAllReady

This fix addresses issue facebook#34966 where renderToPipeableStream with the onAllReady
callback incorrectly injected streaming scripts and hidden HTML elements even when
all content was fully loaded.

Changes:
- Modified flushSegment in ReactFizzServer.js to check allPendingTasks > 0 before
  outlining Suspense boundaries
- Modified flushCompletedQueues in ReactFizzServer.js to skip blocking shell
  instructions when allPendingTasks === 0
- Modified writeCompletedRoot in ReactFizzConfigDOM.js to only emit template tag
  when not complete
- Updated test snapshots to reflect new behavior (no streaming instructions when
  using onAllReady)
- Added new test file ReactDOMFizzServerNodeIssue34966-test.js to verify the fix

This prevents unnecessary streaming scripts and hidden elements from being injected
when using onAllReady for SEO crawlers, improving SEO scores.

Co-Authored-By: Vedant Khanna <[email protected]>
@meta-cla
Copy link

meta-cla bot commented Oct 25, 2025

Hi @VedantKh!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@meta-cla
Copy link

meta-cla bot commented Oct 25, 2025

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla bot added the CLA Signed label Oct 25, 2025
@Avepy
Copy link

Avepy commented Oct 25, 2025

Hey! There is an existing PR that addresses this exact issue - #34969
Reading through both, the code and tests here substantially duplicate #34969
Please propose improvements on the existing PR instead of creating a parallel duplicate, and add proper attribution if reusing code

@Bobadu
Copy link

Bobadu commented Oct 25, 2025

@VedantKh

This PR appears to be a duplicate of my work in #34969, which was created 4 hours earlier.

  1. Timeline: My PR [Fizz] Don't emit streaming instructions when using onAllReady #34969 was created at 2025-10-24 17:51:59 +0200, this PR was created ~4 hours later
  2. Identical implementation: Both PRs modify the exact same files with the same logic:
    • ReactFizzServer.js: Check allPendingTasks > 0 before outlining
    • ReactFizzServer.js: Set skipBlockingShell = true when allPendingTasks === 0
    • ReactFizzConfigDOM.js: Only emit template when not complete
  3. Your PR title: "Fix [Fizz] Don't emit streaming instructions when using onAllReady #34969" references MY pull request number, not the issue (Bug: [19.2.0] Streaming scripts injected in onAllReady in renderToPipeableStream and prerenderToNodeStream #34966)

**In open source when someone has already submitted a solution, you should review/collaborate on that PR, not create a competing one... If you want to improve an existing PR, you can offer suggestions or request to contribute commits. Creating a duplicate PR 4 hours later, especially using AI, is not appropriate

Please close this PR as a duplicate of #34969. If you have improvements to suggest, I'm happy to review them on my PR.

U even use my comments 🤦‍♀️


Proof of my original work:

@VedantKh
Copy link
Author

VedantKh commented Oct 25, 2025

@Bobadu and @Avepy

Apologies! I was testing an applet I built that automatically reviews GitHub Issues and submits PRs with a single click, and I clicked on the issue you submitted a PR to without looking into it too deeply. The agent probably noticed your work and took heavy inspiration from it. Didn't mean to take any undue credit!

@Avepy
Copy link

Avepy commented Oct 25, 2025

If you have any improvement feel free to suggest changes in #34969 so everything will be in one place and you will be then co-author of the changes made

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: [19.2.0] Streaming scripts injected in onAllReady in renderToPipeableStream and prerenderToNodeStream

3 participants