-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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(nuxt): clone app config on server #20278
Conversation
Β Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
I like it. We donβt need to make it reactive on SSR either to attach to nuxtApp instance |
Thank you! You might also consider using |
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.
Nice find but appConfig
is not supposed to be shared across requests same. One of the main fundamental goals is that it can be modified per-request basis so it needs to be bound to nuxt app instance. Making things like remote-config possible but not limited to this only.
We might try structured cloning or simply a deep clone on first edit (via a proxy)
Since originally suggesting
Having said that, I think we have two options. (More ideas welcome.)
Thoughts welcome. |
Regarding nitro, I'm thinking to also make it also stricter to require composable utils like We could fall back to the frozen version of the app config-if nuxt app context is not available to avoid introducing another utility but i would even make a warning for that. App config logic should be context aware. Wdyt? |
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.
(discussion to be resolved it is not stale)
Updated (and following unjs/nitro#1154 to use |
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.
LGM. Nice solution π―
β Type of change
π Description
Calling
reactive
on an object mutates the object, so previously we were causing a memory leak by mutating app config (as the underlying object was shared between requests). Instead, this PR clones the object on server side - and does not make it reactive. This might help with #20056 (although I can't verify for sure as there is no reproduction).Additionally, as app config is shared across requests anyway, I don't believe we need to set it onNuxtApp
as well. This frees us up to use app config ambiently, not necessarily in a plugin/setup context. We can also somewhat reduce the implementation size by getting rid of a workaround for Vite HMR.I would welcome context/discussion if you think differently - an alternative solution would be to use structuredClone or equivalent + not calling reactive on the app config.π Checklist