-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
[Fizz] Track Key Path #27243
[Fizz] Track Key Path #27243
Conversation
Tracks the currently executing parent path of a task, using the name of the component and the key or index. This can be used to uniquely identify and instance of a component between requests - assuming nothing has changed.
const props = element.props; | ||
const ref = element.ref; | ||
const name = getComponentNameFromType(type); |
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.
Since we're going to go check the type again in renderElement, we could move this code deeper and extract the name in each slot but there's so much code duplication I stayed away from that even though that's my usual M.O.
if (isArray(node) || getIteratorFn(node)) { | ||
// Nested arrays behave like a "fragment node" which is keyed. | ||
// Therefore we need to add the current index as a parent key. | ||
task.keyPath = [task.keyPath, '', childIndex]; |
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 is subtle but the first array inside of a component is the same as having a single element with slot 0
. So the array itself doesn't take up slot 0
. In other words, we the outer most array doesn't get added to the path but the next one gets treated as if it was a fragment element in that slot.
This will allocate quite a lot of nodes but hopefully the young generation collector takes them quick. A possible alternative implementation could push/pop to an array in the recursive path and clone whenever it spawns a new task. We don't do that for contexts but it might make more sense for this one. |
Tracks the currently executing parent path of a task, using the name of the component and the key or index. This can be used to uniquely identify an instance of a component between requests - assuming nothing in the parents has changed. Even if it has changed, if things are properly keyed, it should still line up. It's not used yet but we'll need this for two separate features so should land this so we can stack on top. Can be passed to `JSON.stringify(...)` to generate a unique key. DiffTrain build for [98f3f14](98f3f14)
### React upstream changes - facebook/react#27265 - facebook/react#27259 - facebook/react#27264 - facebook/react#27257 - facebook/react#27258 - facebook/react#27187 - facebook/react#27243 - facebook/react#27205 - facebook/react#27220 - facebook/react#27238 - facebook/react#27234 - facebook/react#27224 - facebook/react#27223 - facebook/react#27222 This will help unblock #53906
Tracks the currently executing parent path of a task, using the name of the component and the key or index. This can be used to uniquely identify an instance of a component between requests - assuming nothing in the parents has changed. Even if it has changed, if things are properly keyed, it should still line up. It's not used yet but we'll need this for two separate features so should land this so we can stack on top. Can be passed to `JSON.stringify(...)` to generate a unique key.
Tracks the currently executing parent path of a task, using the name of the component and the key or index. This can be used to uniquely identify an instance of a component between requests - assuming nothing in the parents has changed. Even if it has changed, if things are properly keyed, it should still line up. It's not used yet but we'll need this for two separate features so should land this so we can stack on top. Can be passed to `JSON.stringify(...)` to generate a unique key. DiffTrain build for commit 98f3f14.
Tracks the currently executing parent path of a task, using the name of the component and the key or index.
This can be used to uniquely identify an instance of a component between requests - assuming nothing in the parents has changed. Even if it has changed, if things are properly keyed, it should still line up.
It's not used yet but we'll need this for two separate features so should land this so we can stack on top.
Can be passed to
JSON.stringify(...)
to generate a unique key.