-
Notifications
You must be signed in to change notification settings - Fork 47.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider Text node in the root hydration #31097
Closed
+21
−4
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite right b/c the instance is refined to Element below and text nodes aren't elements. But I see what are you are trying to do. As commented below we're being somewhat conservative here but if you could make the case that there is widespread use of extensions/scripts that insert text nodes in the body before primary content then we can consider changing the heuristic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah so frameworks uses text nodes as a reference to a fragment because DocumentFragment loses their children reference when appended in the dom. Or also the React portal adds text around portal nodes.
Our use case is that pieces of the page like a header are rendered outside of React as inline scripts. We use suppressHydrationWarning for those DOM tree, but they also have portal similar implementation to render elements on the body causing the issue when the script is loaded.
example of React Portal rendered tree from the documentation as an example of the approach used
![Screenshot 2024-09-30 at 4 44 59 PM](https://private-user-images.githubusercontent.com/2222191/372277804-d0e1c11b-5766-4d84-9010-a91904c908d1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk3MTc2OTEsIm5iZiI6MTczOTcxNzM5MSwicGF0aCI6Ii8yMjIyMTkxLzM3MjI3NzgwNC1kMGUxYzExYi01NzY2LTRkODQtOTAxMC1hOTE5MDRjOTA4ZDEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTZUMTQ0OTUxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Njc0NTVjNTVjNjgwNjY2Mjg3ZTg0YWIzODQ1MWU5M2Y5NzRlODUwNzlmZTZiMzFkNzg3YmQ3MTk4Njg1NmYwYSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.K1hGOzylbVYlhB1HIrNIB9OllFgR_WaCz1A3QEM4JCo)