-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Supported cloneVNode use-case? #1426
Comments
If use the Current behavior is expected.Because you add extar props with If you want remove |
@underfin I'm not suggesting that you use the Rather, I suggest you combine the
That is not always practical.
|
@jods4 Sorry for I'm not completely get your first said =.=
This is necessary with use patchFlags from the new node. Example, the previous node is a element but the new node is a component.That will get error as use patchFlags from the previous node.
I agree with you if use |
No worry. |
Thanks for your explain :) Are you mean add the code If this is your idea, I think it is useful under this situation. |
Yes, something like that. let { patchFlag, dynamicChildren, dirs } = n2;
// Consider both previous and new node because either one might have been replaced with cloneVNode or similar.
patchFlag |= (n1.patchFlag & PatchFlags.FULL_PROPS); |
What problem does this feature solve?
cloneVNode
is public API for advanced scenarios.I'm unsure what you're allowed to do with it or not and I encountered an interesting pitfall.
I have created a render function that manipulates its slot.
Basically:
cloneVNode(original, { class: 'added-stuff' })
Based on this example, the
added-stuff
class is correctly rendered in DOM when added.But when, based on state, I stop modifying the child and use the original vnode instead, the class is not removed.
I don't know if this is a supported scenario but I have traced the root cause of this.
It doesn't reproduce always, it depends on the original node and its patchFlags.
When cloning,
cloneVNode
changes thepatchFlags
to deoptimize dynamic props, given you might have changed any props. That's why the added stuff always appear.But when returning back to the original, it has optimized
patchFlags
and only looks at the dynamic props, neglecting that it might lack the props added by the clone.In my tests, when I hack the
patchFlags
of the original, everything works as expected.What does the proposed API look like?
If what I'm doing is not completely crazy, then I suggest the following fix:
When comparing vnodes, instead of using the
patchFlags
from the new node only, combine it with thepatchFlags
from previous node.In normal situations they'll be the same anyway.
In cases where you swap a node with a modified
cloneVNode
, that will use the less optimizedpatchFlags
and make both directions (original -> clone, then clone -> original) work.The text was updated successfully, but these errors were encountered: