-
Notifications
You must be signed in to change notification settings - Fork 47.7k
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
Add ref to Fragment (alternative) #32465
Open
jackpope
wants to merge
13
commits into
facebook:main
Choose a base branch
from
jackpope:fragment-refs-alt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,049
−29
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
45b29da
Add enableFragmentRefs feature flag
jackpope ae68e1d
Create and attach fragment instances
jackpope 18f8999
Remove public append/remove child APIs
jackpope f5bfe1c
Handle children with multiple fragment parents
jackpope f4a88bd
Add basic order preservation test
jackpope 579d123
Dont store children on fragment instance, calculate at time of operation
jackpope 1c2bbce
Handle Activity mode switch
jackpope 67efec9
clean up
jackpope 87d09a8
Fix traversal order, remove focus mocks
jackpope 3646ec8
Set stateNode in commit phase
jackpope 533e0b6
Refactor fragment parent traversal to avoid allocations
jackpope 5258f5b
Avoid allocations while traversing host children
jackpope e08683f
Keep fiber reference up to date
jackpope 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
Oops, something went wrong.
Oops, something went wrong.
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.
You set this only once but that will be the initial Fiber which means that any time you traverse it, you'll observe the initial state of the tree. Because of alternate model you have a 50/50 chance of getting it right but you might actually get the alternate and not
current
here.Instead, you need to update this to the new Fiber any time a new one commits. Basically in
commitMutationEffectsOnFiber
on the Fragment branch you update it.Technically you only need to update it if there are Placement/Deletion in the subtree but that would hold on to an old Fiber for longer and would be confusing. So you might as well always update it.
Note that this is what we do for HostComponents too but only for props, but we should probably just update the Fiber instead.
https://github.com/facebook/react/blob/main/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js#L773
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.
Thanks for the catch! This definitely revealed bugs once I logged the current state of the fiber tree after Placement/Deletion. I just didn't have a test yet that asserted on anything requiring the traversal of a newly added node. I've updated to set
current
's reference tofinishedWork
incommitMutationEffectsOnFiber