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
feat(nuxt): warn when page uses a layout without <NuxtLayout>
#24116
Conversation
Run & review this pull request in StackBlitz Codeflow. |
Agh, I commited to my |
<NuxtLayout>
is created
<NuxtLayout>
is created<NuxtLayout>
is created
Please could the CI be re-run, I think it's an unrelated timeout. |
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.
This is a nice improvement π
Codecov ReportAll modified and coverable lines are covered by tests β
Additional details and impacted files@@ Coverage Diff @@
## main #24116 +/- ##
=======================================
Coverage ? 58.76%
=======================================
Files ? 5
Lines ? 861
Branches ? 46
=======================================
Hits ? 506
Misses ? 355
Partials ? 0 β View full report in Codecov by Sentry. |
<NuxtLayout>
is created<NuxtLayout>
Question: what about if you only ever declare your layouts for your page components in
|
@nathanchase That should be totally fine and is recommended. What is the issue you are experiencing? |
With the nightly build, I was noticing the warning that I had layout files but didn't use |
Were you visiting a page with a layout defined in metadata, but not using |
Correct. |
Well, then that's exactly what this PR is meant to warn against. You have defined a layout for a page but aren't displaying that layout. Or am I missing something? |
No, I have the layout defined in the meta tag, but is that not enough to indicate that the page should be automatically wrapped by that layout? Are you meant to additionally add a |
No, just And this isn't a change. It's not automatically added, which is why we created this PR. Layouts can be used on their own or separately so you need to add it to your |
What about nested layouts? Example: Then I have another layout (
Then in a page component, I reference the
This has worked without issue until now. |
Perhaps you had better create a new issue with a reproduction. This PR did not change the actual behaviour at all, only added some console logging to avoid users expecting to see a layout but not seeing one because they forgot to add |
Perhaps it is the absence of an app.vue altogether? |
I still don't understand the issue you're having. |
The problem is that I've been using layouts for months and it all works as expected, but this PR seems to think I was doing it incorrectly and sends a warning that I'm not using |
So you are using it. That sounds like a bug in how we are detecting usage, then. Could you create a reproduction? |
π Linked issue
#19392
β Type of change
π Description
Resolves #19392 by adding a warning in development if layouts are present but the
<NuxtLayout>
component has not been used. All changes are dev-only and should be tree-shaken out.We first add a new variable
nuxtApp.payload._isNuxtLayoutUsed
which isfalse
by default. When the<NuxtLayout>
component is declared, this is switched totrue
. A new plugin is added which runsonNuxtReady
. If Nuxt Layout has not been used, then it counts the layouts registered and if this is greater than 0, displays a warning.#build/layouts
provides the layouts in the src directory, as well as in any layers.π Checklist