nuxt / nuxt

The Intuitive Vue Framework.
https://nuxt.com
MIT License
54.95k stars 5.03k forks source link

definePageMeta doesn't work/ gets ignored #27943

Closed cxo-jutz closed 4 months ago

cxo-jutz commented 4 months ago

Environment

"nuxt": "^3.10.1",
"vue": "^3.4.21",

Reproduction

Minimal example - here it seems to work as intended tho: https://codesandbox.io/p/sandbox/stoic-star-y6tk4z

In app.vue is simply

<template>
    <NuxtLayout>
        <NuxtPage />
    </NuxtLayout>
</template>

defined. And in pages is the layout (which is in /layouts (default.vue, test.vue) with definePageMeta

<script setup lang="ts">
definePageMeta({
    layout: 'test',
});
</script>

Describe the bug

Only since a few days without any recall of change regarding these files, we noticed that on the checkout and account pages it will always load the default layout now. If we add a console.log right underneath the definePageMeta it shows up, so the file itself etc is the correct, just the right layout isn't applied anymore.We tried updating the packages but even that didn't change the behavior, same with cache and a fresh dev start. I've also read through https://github.com/nuxt/nuxt/issues/13354 which seemed to be the same bug, but we have the NuxtPage wrapping the NuxtLayout in the app.vue.

Any clues/ ideas on which direction we could debug would be highly appreciated! local_nuxt_behavior

Additional context

No response

Logs

No response

github-actions[bot] commented 4 months ago

Would you be able to provide a reproduction? πŸ™

More info ### Why do I need to provide a reproduction? Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making. ### What will happen? If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritize it based on its severity and how many people we think it might affect. If `needs reproduction` labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it. ### How can I create a reproduction? We have a couple of templates for starting with a minimal reproduction: πŸ‘‰ https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz πŸ‘‰ https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox A public GitHub repository is also perfect. πŸ‘Œ Please ensure that the reproduction is as **minimal** as possible. See more details [in our guide](https://nuxt.com/docs/community/reporting-bugs/#create-a-minimal-reproduction). You might also find these other articles interesting and/or helpful: - [The Importance of Reproductions](https://antfu.me/posts/why-reproductions-are-required) - [How to Generate a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/minimal-reproducible-example)
cxo-jutz commented 4 months ago

I am unsure about the why but at our project it seemed to be fixed by removing the second script tags with

<script lang="ts">
export default {
  name: "TestPage",
};
</script>
fletcherhaz commented 2 months ago

We have some files which export GraphQL Fragments in the non-setup script tag, so removing it wasn't an option. Thankfully, simply moving definePageMeta to the <script> tag without setup fixed the issue. Might be worth adding a note about that to the documentation, but leaving this here for anyone who finds the issue.

However, I am getting warnings like this:

definePageMeta() is a compiler-hint helper that is only usable inside the script block of a single file component which is also a page. Its arguments should be compiled away and passing it at runtime has no effect.
fenn1ks commented 2 months ago

i updated nuxt to 3.13.0 Have same problem with definePageMeta

danielroe commented 2 months ago

Please open a new issue with a reproduction if you are facing this. Several similar issues have been resolved, which is why this is closed.

fletcherhaz commented 2 months ago

27845 is the duplicate issue being referred to that has the pull request attached. Version 3.13.0 should have the fix in it, I think.

fenn1ks commented 2 months ago

@danielroe @fletcherhaz i use 3.12.4 and 3.13.0 and i have this problem, but when i install 3.11.2 - all okay okay i open new "issues"