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

can not update createVNode instance #9975

Closed
tangjinzhou opened this issue Jan 3, 2024 · 5 comments
Closed

can not update createVNode instance #9975

tangjinzhou opened this issue Jan 3, 2024 · 5 comments

Comments

@zhou5631
Copy link

zhou5631 commented Jan 3, 2024

老师来发声了,赞赞赞

@cc-hearts
Copy link

Can you set effect.dirty to true before calling update?

For example like this: playground

@tangjinzhou
Copy link
Contributor Author

tangjinzhou commented Jan 3, 2024

Can you set effect.dirty to true before calling update?

For example like this: playground

component.update is not public api. effect.dirty also not public api. we should avoid use this. However, due to historical reasons, if the official can support solving the component.update problem. Historical versions will be compatible. If not, we will use public api to reconstruct this code as much as possible instead of not safe api again.

@pikax
Copy link
Member

pikax commented Jan 3, 2024

Using internal API/behaviours can cause these sort of issues, since they are not public they might not be tested directly and the tests are done by other places that rely on that behaviour.

My personal opinion and not talking as Vue team or any official manner:

I think there's an incorrect usage of the internal function but on the other hand I would expect .update to be a very similar behaviour to $forceUpdate which would trigger a re-render regardless of dependencies. Is also odd that the stateful component works and stateless does not, making me think this might be a bug, altho in template usages it works as expected.
As for effect.dirty = true, there's some usages in the code base to trigger this exact behaviour, I cannot recommend that, because there's no guarantee it will keep working in the future.

One way to solve this in most of v3 releases is to use cloneVNode to update the node:

// vm.component.update()
// I don't really recommend updating/mutating the props directly
VueRender(cloneVNode(vm, vm.component.props), domRef.value)

@yyx990803
Copy link
Member

yyx990803 commented Jan 4, 2024

The correct usage with public APIs: for each update, you should be creating a new vnode with the new props and then call render again on the same DOM container:

const handleClick = ()=> {
-  Object.assign(vm.component.props, {num: ++num})
-  vm.component.update();
+  VueRender(createVNode(CompFunctional, { num: ++num }), domRef.value)
}

Demo

Closing as wontfix, as the workaround is relatively straightforward.

@yyx990803 yyx990803 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jan 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants