-
-
Notifications
You must be signed in to change notification settings - Fork 9.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: vite devmode with storyStoreV6 by ensuring singleton via global #20207
Fix: vite devmode with storyStoreV6 by ensuring singleton via global #20207
Conversation
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.
Can you explain why we need to do this @ndelangen?
(a) for v6: I would expect that loading the start.js
file several times would be bad news even if the preview is "singleton-ized" (e.g. we would potentially add the user's decorators etc more than once)
(b) for v7: if this is a bug in v6, why do we need to update the modern entries? I don't love the idea of writing the code to expect it to be loaded >1 times when we don't want it to be.
@tmeasday we need to do this, because unfortunately there's some bug in the vite dev mode, that makes it skip transforming a file. I figured I'd do the change on both, to avoid the future question of: "why is this only done for a, and not for b?" Make the change more uniform, so it's less unexpected.
Maybe this isn't a problem with Vite4? I'd need to try, but I think ensuring these things to be singletons isn't the worst we could do. |
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.
As discussed we can drop the changes to all the entry points and mostly confine this to ClientApi.ts
.
The rationale is as follows:
- The entry points /
start.ts
can only run once no matter what. If they ran more than once, there'd be major problems with multiple channels etc. - Those entry points create the "real" client api / preview and set it on global scope.
- In the v6 store, we also evaluate previewAnnotation files (e.g. preview.js) and call eg.
addParameters()
fromClientApi
. The problem comes when that version ofClientApi
is wrong, and it's singleton is not initialized. However if it reads the singleton from global scope, like you do in this PR, we bypass the issue, as the singleton was already set on global scope by the entrypoint.
91fe4d8
to
775f3ae
Compare
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.
Lgtm
🎉 |
Related: #20184
What I did
Ensure we only create a single instance of ClientApi
How to test?
code/ui/.storybook.ts
so it usesstoryStoreV7: false
yarn storybook:ui
incode
.I tested this locally.