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
Calling setPageLayout() before page mount does not render properly #15176
Comments
You need to call |
I can take care of this. |
Also a good idea. 👍 |
So just to clarify this: It should work when calling I adjusted the repro to this premise, but it still doesn't seem to work as I'd expect: https://stackblitz.com/edit/github-t7y38h-murv6p?file=pages%2Findex.vue |
No, it should not work calling in setup during SSR. On server, it only works before the layout starts to be rendered, so in a plugin. |
Okay, not aware of what exactly this means yet, need to do some reading about server-side plugin magic I guess. Thanks for clarifying! |
The issue is that server renders top down, outside in, and is not reactive. So if you change the layout (which has already been rendered) in a child component, this will lead to wrong HTML. The layout can't be rerendered to HTML; that ship has sailed. |
In conclusion, we nerver can't do this (in nuxt default ssr mode)? |
Environment
Output of
npx nuxi info
from the provided StackBlitz (although I have also locally tested this with a recent edge release).RootDir: /home/projects/github-t7y38h
Nuxt project info:
Linux
v16.14.2
3.0.0-rc.11
0.5.4
npm@7.17.0
vite
-
-
-
Reproduction
See this Stackblitz: https://stackblitz.com/edit/github-t7y38h?file=pages/index.vue
Describe the bug
Calling
setPageLayout()
directly during the page component's setup (i.e. before the page has been mounted) will change most of the layout's template correctly, but will not apply root classes correctly.EDIT: As I noticed after creating the reproduction project above, the problematic behavior is not strictly limited to the root element. The problem persists even when wrapping the layout's root element in another
<div>
layer, so here's an alternative Stackblitz with the adjusted template structure: https://stackblitz.com/edit/github-t7y38h-cueidk?file=pages/index.vueAdditional context
The reason for using
setPageLayout()
overdefinePageMeta()
in my case is that I'm getting the page's layout from a third party endpoint withuseAsyncData()
. However, doing that is not necessary to reproduce the behavior.Logs
No response
The text was updated successfully, but these errors were encountered: