Skip to content
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

fix: add selector type to all vnodes #4234

Merged
merged 4 commits into from
May 29, 2024
Merged

Conversation

jmsjtu
Copy link
Member

@jmsjtu jmsjtu commented May 29, 2024

Details

By expanding static content optimization to more nodes we've revealed a bug with the existing diffing algo.

In special circumstances when a text vnode is compared against a static vnode they will be considered the same vnode because we use the sel and key to determine vnode equality.

Since both text and static vnodes have an undefined key and sel values they are incorrectly evaluated.

This PR updates the values of sel to distinguish these vnodes and prevent future false positives.

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.

GUS work item

@jmsjtu jmsjtu requested a review from a team as a code owner May 29, 2024 21:27
// Empty fragment
expect(ul.children.length).toBe(0);

const spy = spyConsole();
Copy link
Member Author

@jmsjtu jmsjtu May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm importing the spy directly because the error is logged by the engine and can't be caught directly when elm.items = [{ value: 1 }].

Copy link
Contributor

@nolanlawson nolanlawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@ekashida ekashida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is sel always defined now? If so, should we update the type definition for BaseVNode?

@jmsjtu
Copy link
Member Author

jmsjtu commented May 29, 2024

Is sel always defined now? If so, should we update the type definition for BaseVNode?

@ekashida looks like scoped slot fragment vnode is the only one left with undefined sel.

@nolanlawson
Copy link
Contributor

@jmsjtu Might as well add sel everywhere? 🤷

@ravijayaramappa
Copy link
Contributor

Agree with Nolan's comment, ScopeSlotFragment can get a sel too.

Copy link
Member

@ekashida ekashida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤞

@ekashida ekashida changed the title fix: add selector type to fragment, text, comment, and static vnodes fix: add selector type to all vnodes May 29, 2024
@jmsjtu jmsjtu merged commit 2d304e6 into master May 29, 2024
10 checks passed
@jmsjtu jmsjtu deleted the jtu/set-static-vnode-sel branch May 29, 2024 23:06
jmsjtu added a commit that referenced this pull request May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants