[Flight] Fix isValidElement returning false for elements with a debug channel#36136
Open
976520 wants to merge 1 commit intofacebook:mainfrom
Open
[Flight] Fix isValidElement returning false for elements with a debug channel#36136976520 wants to merge 1 commit intofacebook:mainfrom
976520 wants to merge 1 commit intofacebook:mainfrom
Conversation
… channel When `debugChannel` with a readable stream is provided to `createFromNodeStream`, positions 4 (owner) and 5 (stack) in RSC element tuples reference pending debug chunks. The previous code tracked these as blocking deps, which caused elements to be wrapped in `REACT_LAZY_TYPE` via `createLazyChunkWrapper` — breaking `isValidElement()`, `cloneElement()`, and hydration checks. Track debug-only deps (positions 4/5 with an active debug channel) separately in a new `debugDeps` counter on `InitializationHandler`. Only lazy-wrap when there are real blocking deps beyond debug-only ones. After all debug deps resolve, call `initializeElement()` again so `_debugStack` gets normalized from the raw serialized string into an `Error` object, which is required by `captureOwnerStack` / `formatOwnerStack`. Fixes facebook#36097
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
debugChannelwith a readable stream is provided tocreateFromNodeStream,positions 4 (owner) and 5 (stack) in RSC element tuples reference pending debug
chunks. The previous code tracked these as blocking deps, which caused elements to
be wrapped in
REACT_LAZY_TYPEviacreateLazyChunkWrapper— breakingisValidElement(),cloneElement(), and hydration checks.Fix: Track debug-only deps (positions 4/5 with an active debug channel) separately
in a new
debugDepscounter onInitializationHandler. Only lazy-wrap when thereare real blocking deps beyond debug-only ones. After all debug deps resolve, call
initializeElement()again so_debugStackgets normalized from the raw serializedstring into an
Errorobject, which is required bycaptureOwnerStack/formatOwnerStack.Fixes #36097
How did you test this change?
Added a regression test in
ReactFlightDOMNode-test.jsthat reproduces the bug:renders a server component through a
debugChannel-backed stream with a delayedtransport, deserializes the result, and asserts
React.isValidElement(deserialized) === true.Also verified the existing
"can transport debug info through a slow debug channel"test continues to pass — the owner stack captured during SSR still correctly reflects
the server-side owner even with the delayed debug channel.