-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Fix vue resetting state when using view transition persistence #11946
Fix vue resetting state when using view transition persistence #11946
Conversation
🦋 Changeset detectedLatest commit: bf17ff8 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/integrations/vue/client.js
Outdated
} else { | ||
appInstance.props = props; | ||
appInstance.slots = slots; | ||
appInstance.app._instance.proxy.$forceUpdate(); |
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.
is this how you're supposed to trigger an update? If this is private code we shouldn't do it, and try to find another way.
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.
I checked again and found a better way to call the $forceUpdate
method (which is documented), so I don't think there is any private implementation details used any more.
Changes
This change keeps track of all initialized vue islands in order to update the existing instance rather than creating a new app, which resets the state.
I'm by no means a Vue expert and there might be more elegant ways to achieve this. I tried to follow the approach of the React implementation (using a
WeakMap
), however, patching the props is a bit more difficult than in in React. I'm happy to improve it in case anybody has a better idea.This fixes #11854,
Testing
E2E test was added.
Docs
As this is only a fix, I don't think documentation is needed. However, it could be pointed out that state persistence is currently broken for all frameworks except for React and Vue if I'm not mistaken.