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

Need a new way for plugins to inject their state into nuxtState #9155

Closed
ciscorn opened this issue Apr 15, 2021 · 0 comments · Fixed by #9332
Closed

Need a new way for plugins to inject their state into nuxtState #9155

ciscorn opened this issue Apr 15, 2021 · 0 comments · Fixed by #9332

Comments

@ciscorn
Copy link

ciscorn commented Apr 15, 2021

Is your feature request related to a problem? Please describe.

It is related to issue #8620 ("beforeNuxtRender is called too soon").

Since Vue’s serverPrefetch (onServerPrefetch) and Nuxt’s new fetch (which utilizes Vue’s serverPrefetch) were introduced, beforeNuxtRender is no longer the proper hook for plugins to inject their state into nuxtState.

Nuxt < 2.12
→ asyncData() & fetch() → beforeNuxtRender() → start rendering App → serverPrefetch() → render HTML

Nuxt >= 2.12
→ asyncData() → beforeNuxtRender() → start rendering App → serverPrefetch()fetch() → render HTML

Some plugins such as vue-apollo currently rely on serverPrefetch (onServerPrefetch) to perform the component-level prefetching, and therefore these plugins cannot do the client hydration properly with the current Nuxt.

Some users seems to do a temporary hack as a workaround #8852 (comment).

Describe the solution you'd like

I think Nuxt should provide plugins with a new hook that is suitable for updating nuxtState.

Describe alternatives you've considered

Instead of adding a new hook, we could make Nuxt call beforeNuxtRender() just after the App is rendered if this doesn't cause serious backward compatibility issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants