Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
/frameworkPublic archive

feat(nuxt): add setPageLayout utility (#6826) - #7075

Merged
pi0 merged 4 commits into
mainfrom
feat/set-page-layout
Aug 31, 2022
Merged

feat(nuxt): add setPageLayout utility (#6826)#7075
pi0 merged 4 commits into
mainfrom
feat/set-page-layout

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 Linked issue

resolvesnuxt/nuxt#14710

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This adds a setPageLayout utility to handle complexities associated with changing layout keyed off of route.meta. Namely, it's complicated to persist the change from server -> client. This persists the server-set layout via a custom useState which is only used on the initial hydration. Subsequent layout changes are reactive and don't need to be hydrated.

Originally implemented by @516310460 ❤️

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@danielroedanielroe added enhancement New feature or request pages 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing labels Aug 30, 2022
@danielroe
danielroe requested a review from pi0August 30, 2022 16:04
@danielroedanielroe self-assigned this Aug 30, 2022
@netlify

netlifyBot commented Aug 30, 2022

Copy link
Copy Markdown

Deploy Preview for nuxt3-docs ready!

NameLink
🔨 Latest commit9861f36
🔍 Latest deploy loghttps://app.netlify.com/sites/nuxt3-docs/deploys/630e4b3cf9c6ab0007e62e55
😎 Deploy Previewhttps://deploy-preview-7075--nuxt3-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@pi0

pi0 commented Aug 30, 2022

Copy link
Copy Markdown
Member

Following up nuxt/nuxt#14710, i understand there is a way to use prop binding for global usage of NuxtLayout but I'm thinking we could easily (what I suppose) use _layout state for default value of :name for <NuxtLayout>. This way utility can be already universal as setLayout.

@danielroe

Copy link
Copy Markdown
MemberAuthor

I did consider updating the default value but feel that it's not optimal. Consider this use case:

  1. user visits a blog page (~/pages/blog/[slug].vue). This blog entry is full-width, so we set the layout to full-width using setPageLayout (so that it can be hydrated correctly on client-side).
  2. user changes route to ~/pages/index.vue or ~/pages/about.vue. Now these are also displaying full-width layout unless there is a hard-coded definePageMeta({ layout: 'default }) in the page.

If we want to update the default layout (and I'm not sure we should) then a setDefaultLayout utility or similar might be a better approach.

@HomWang

HomWang commented Aug 30, 2022

Copy link
Copy Markdown
Contributor

I would like to know if there is a possibility of having more than one NuxtLayout in the page and if changing the _layout will be affected

<template>
<div>
<NuxtLayout>
<template #header> Some header template content. default</template>
</NuxtLayout>
<NuxtLayout name="custom">
<template #header> Some header template content. custom</template>
</NuxtLayout>
<NuxtLayout name="custom-two">
<template #header> Some header template content. custom-two</template>
</NuxtLayout>
</div>
</template>

Link: https://stackblitz.com/edit/github-m7s6nu?file=pages%2Findex.vue

@pi0pi0 changed the title feat(nuxt): add setLayout utility (#6826)feat(nuxt): add setPageLayout utility (#6826)Aug 31, 2022
@pi0pi0 changed the title feat(nuxt): add setPageLayout utility (#6826)feat(nuxt): add setPageLayout utility (#6826)Aug 31, 2022
pi0
pi0 approved these changes Aug 31, 2022
@pi0

pi0 commented Aug 31, 2022

Copy link
Copy Markdown
Member

Makes sense to introduce setDefaultLayout utility for universal usage 👍🏼

@pi0
pi0 merged commit b90d286 into mainAug 31, 2022
@pi0
pi0 deleted the feat/set-page-layout branch August 31, 2022 08:02
@pi0pi0 mentioned this pull request Sep 1, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

3.xenhancementNew feature or request🍰 p2-nice-to-havePriority 2: nothing is broken but it's worth addressingpages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setLayout/setPageLayout utility

4 participants

@danielroe@pi0@HomWang@DamianGlowala