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

Wrong layoutName #7567

Closed
usb248 opened this issue Jun 19, 2020 · 22 comments · Fixed by #7606 or #7654
Closed

Wrong layoutName #7567

usb248 opened this issue Jun 19, 2020 · 22 comments · Fixed by #7606 or #7654

Comments

@usb248
Copy link

usb248 commented Jun 19, 2020

Version

v2.13.0

Reproduction link

https://u1rpq.sse.codesandbox.io/

Steps to reproduce

Go to an error page (ex: https://u1rpq.sse.codesandbox.io/not-found), open your debug console, click on home link, see wrong layout. Do hard refresh (F5), layoutName is good now (SSR ok)...
It can be related to #5703, #7554....

What is expected ?

layoutName should be : front

What is actually happening?

layoutName value is: default, it displays default layout instead of front layout

Additional comments?

I use layoutName in order to stylize, it's a very big issue which break all my app.....
I'm missing something ?

This bug report is available on Nuxt community (#c10812)
@ghost ghost added the cmty:bug-report label Jun 19, 2020
@syropian
Copy link

I'm also running into this, client-side renders only seem to render the default layout, while server-side renders seem to correctly render whatever is passed to the layout option.

@usb248
Copy link
Author

usb248 commented Jun 20, 2020

layoutName is always default even if default.vue layout doesn't exist. It's totally buggy...

@fikrivoxel
Copy link

i think its version v2.13.0 make bug layout, maybe downgrade or wait for fix bug

@galvez
Copy link

galvez commented Jun 21, 2020

@usb248 thanks for the report, I'm looking into it.

@usb248
Copy link
Author

usb248 commented Jun 21, 2020

Thx @galvez , I look forward to the fix.

@taras1313
Copy link

taras1313 commented Jun 21, 2020

Hey, here is my temporal workaround to handle this issue.
In your error.vue layout put

<script>
  export default {
    name: 'error',
    layout: 'empty',
    beforeDestroy() {
      $nuxt.setLayout('default') // this line is basically the 'fix'
    },
  };
</script>

Agree, that's not a great solution, but if this bug is critical for you it should work fine until it's fixed.

https://codesandbox.io/s/prod-forest-319td?file=/layouts/error.vue

@Omarillo
Copy link

yes, i have the same issue

@jackiboy
Copy link

Same issue with me. The initial server side render uses the correct layout but once you start navigating through the app with client side routing it renders the default layout.
I have rolled back to v2.12.2 for now.

@Atinux Atinux self-assigned this Jun 23, 2020
@pi0 pi0 mentioned this issue Jun 23, 2020
@Atinux Atinux closed this as completed in 6332aaa Jun 23, 2020
@Atinux Atinux reopened this Jun 23, 2020
@Atinux
Copy link
Member

Atinux commented Jun 23, 2020

Let's closed when v2.13.1 lands, I am really sorry about this regression 😬

@gnuletik
Copy link

Here's another flavour of @taras1313's workaround:
It's based on nuxt-composition-api and it handles destination page with another layout name than 'default'.

import {
  defineComponent,
  useContext,
  getCurrentInstance
} from 'nuxt-composition-api'

export default defineComponent ({
  layout: 'fullpage',
  props: {
    error: {
      type: Object,
      required: true
    }
  },
  setup () {
    const { route } = useContext()

    // FIXME: https://github.com/nuxt/nuxt.js/issues/7567
    onBeforeUnmount(() => {
      const vm = getCurrentInstance()
      if (!vm) {
        return
      }
      const matched = route.value.matched[0]
      vm.$nuxt.setLayout((matched?.components?.default as any)?.options?.layout || 'default')
    })
  }
})

Hope it helps until v2.13.1 gets released.

Thanks for the fix @Atinux !

@pi0
Copy link
Member

pi0 commented Jun 24, 2020

Hi! This should be fixed with v2.13.1.

@pi0 pi0 closed this as completed Jun 24, 2020
@jonian
Copy link

jonian commented Jun 24, 2020

Hi @pi0, this issue is still present in 2.13.1. Using the workaround from @gnuletik or @taras1313 is not optimal as the layout change is visible (page components are loaded before the layout change). Is there a better workaround?

@usb248
Copy link
Author

usb248 commented Jun 24, 2020

There is someone of core team able to fix/understand this issue please ... ? 😟

@pi0 pi0 reopened this Jun 24, 2020
@Atinux
Copy link
Member

Atinux commented Jun 24, 2020

@usb248 you codesandbox is working now with the latest version: https://u1rpq.sse.codesandbox.io/not-found and then navigate to home page

I am not sure to understand what's the issue now 🤔

@Atinux
Copy link
Member

Atinux commented Jun 24, 2020

@jonian could you provide a reproduction please?

It works perfectly for us: https://codesandbox.io/s/frosty-fog-homlr

@jonian
Copy link

jonian commented Jun 24, 2020

@Atinux, reproduction at https://codesandbox.io/s/fervent-hoover-bq5nq. I can also reproduce this with a new app locally. Home and About pages use the default layout. Error page/layout uses the empty layout.

What fixes the issue for me is replacing https://github.com/nuxt/nuxt.js/blob/dev/packages/vue-app/template/client.js#L612

if (this._hadError) {
  Vue.nextTick(() => {
    this.setLayout(layout)
  })
} else {
  this.setLayout(layout)
}

@jonian
Copy link

jonian commented Jun 24, 2020

@Atinux, when error page uses the default layout and Home, About use the front layout, it works as expected. Reproduction at https://codesandbox.io/s/pensive-glade-hkpfl. So it looks that the issue occurs when assigning a layout to the error page.

@piecedata
Copy link

piecedata commented Jun 25, 2020

I do also have like @jonian

Homepage is using orange layout, error page is using empty layout. When I hit go to homepage link from error page the layout is not updated to orange but remains the empty layout, but must be orange as set for homepage. Im using nuxt 2.13.1

If I do not assign a layout to the error page, everything works as expected.

@pi0
Copy link
Member

pi0 commented Jun 25, 2020

Bug still exists. The issue is that setLayout from App:render is being called for error layout when navigating from404 to / (last console log)

image

We are working to find a fix :)

@pi0 pi0 mentioned this issue Jun 26, 2020
@pi0
Copy link
Member

pi0 commented Jun 26, 2020

Hi. This should be (finally) fixed with v2.13.2 apologizes for all inconveniences due to this bug.

@usb248
Copy link
Author

usb248 commented Jun 26, 2020

Thanks, it's ok for me

@usb248 usb248 closed this as completed Jun 26, 2020
@jonian
Copy link

jonian commented Jun 30, 2020

@pi0, @Atinux, PR #7606 causes wrong error layout when there are errors after the route is mounted (eg. 500 errors).

Reproduction at https://codesandbox.io/s/affectionate-johnson-1bzfy, error pages should use the empty layout, all other pages should use the default layout.

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