question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calling setPageLayout() before page mount does not render properly

See original GitHub issue

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:


  • Operating System: Linux
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-rc.11
  • Nitro Version: 0.5.4
  • Package Manager: npm@7.17.0
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

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.vue

Additional context

The reason for using setPageLayout() over definePageMeta() in my case is that I’m getting the page’s layout from a third party endpoint with useAsyncData(). However, doing that is not necessary to reproduce the behavior.

Logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
loilocommented, Oct 17, 2022

I can take care of this. That said, if this is easily detectable, it might be useful for this function to console.warn something when used inappropriately.

0reactions
danielroecommented, Oct 17, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Render a page after its layout is fully mounted in Nuxt
In this case, I expect beforeMount to be done in myLayout.vue ,. but myPage.vue does not wait and get mounted before Vuex action...
Read more >
Full DOM Rendering · Enzyme - GitHub Pages
Full DOM rendering requires that a full DOM API be available at the global scope. This means that it must be run in...
Read more >
Unit Testing in React: Full Guide on Jest and Enzyme Testing
Everything is fine when I test a small component without logic, just UI rendering, but as practice shows, there are no such components...
Read more >
Testing React Components with react-test-renderer, and the ...
When you mount a component with react-test-renderer you're interacting with a pure JavaScript object, a representation of the React component.
Read more >
Why I Never Use Shallow Rendering - Kent C. Dodds
The user doesn't care one bit what things are called. In fact, that test doesn't even verify that the message is hidden properly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found