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

Layout slots not working in default layout #15158

Closed
toniengelhardt opened this issue Oct 15, 2022 · 8 comments
Closed

Layout slots not working in default layout #15158

toniengelhardt opened this issue Oct 15, 2022 · 8 comments

Comments

@toniengelhardt
Copy link
Contributor

Environment

Nuxt 3.0.0-rc.11

Reproduction

StackBlitz: https://stackblitz.com/edit/nuxt3-layout-slot-bug

Describe the bug

Layout slots not working with default layout, generate error (see reproduction):

Error: Codegen node is missing for element/if/for node. Apply appropriate transforms first.

Note the use of app.vue.

Explicitly using <NuxtLayout> with layout: false in page meta works but leads to full re-render of the layout and kinda defies the purpose of a default layout.

Not sure if I'm doing something wrong with the setup, but following the docs, the code in the repro should work. Also, best in terms of DX IMO.

Additional context

This is a typical use case where you for instance have a nav and want to add additional items via a slot on specific pages.

Logs

No response

Copy link
Member

Unfortunately this isn't valid vue and the only way to use custom slots is with layout: false as documented. It's a nice idea for enhancement (but would require a compiler plugin to implement, as well as tooling update in volar and other libraries).

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Oct 15, 2022
@toniengelhardt
Copy link
Contributor Author

toniengelhardt commented Oct 15, 2022

@danielroe would it at least be possible to avoid re-rendering the layout if it stays the same, like in the 'this works' case?

Copy link
Member

danielroe commented Oct 15, 2022

That is absolutely something on my list, and currently pending vuejs/core#6736.

(It's not currently possible due to vue behaviour, but should be once that PR merges.)

@toniengelhardt
Copy link
Contributor Author

Amazing, thanks 🙏🏽 I think that is a feasible workaround.

@TJacoob
Copy link

TJacoob commented Nov 5, 2022

Just to add to this, I think it makes some sense as an enhancement. A simple use case would be to have a layout where the screen is split in half, with a slot for each side, and in each page would pass different data to each slot.

For example, login / signup pages often follow the same layout but might have different forms on the screen, along with different texts and information.

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
@VladimirCores
Copy link

Could it be implemented with an additional Nuxt component, something like: <NuxtLayoutSlot name="nav-items"/> with Teleport or something else? Because its a very expected behavior, the way to propagate components to slots in NuxtLayout like in this-doesnt-work example.

@lubomirblazekcz
Copy link

@danielroe I can see that layout still re-renders even if it's the same layout, is there any workaround for this yet?

@danielroe
Copy link
Member

@lubomirblazekcz Would you open a new issue with a reproduction?

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

No branches or pull requests

5 participants