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

Reactivity broken after redirecting from a plugin (nuxt generate) #737

Closed
SherifGhoz opened this issue May 27, 2020 · 11 comments · Fixed by #753
Closed

Reactivity broken after redirecting from a plugin (nuxt generate) #737

SherifGhoz opened this issue May 27, 2020 · 11 comments · Fixed by #753
Labels

Comments

@SherifGhoz
Copy link

SherifGhoz commented May 27, 2020

Hello,

after redirection happens, the page is translated successfully, but the head content doesn't change (title, meta description ... etc)

the problem is only when using nuxt generate (using Netlify).

Locally, it works, title changes.

reproduce the issue:
1- open website from a browser with default language french:
https://tender-raman-68344c.netlify.app/

2- the url will be (https://tender-raman-68344c.netlify.app/fr) and the body content will be ("francais") till now everything is ok... but page title remains ("english") 😞

code is here:
https://codesandbox.io/s/github/SherifGhoz/redirection-issue
https://github.com/SherifGhoz/redirection-issue

Is there any solution ?

@SherifGhoz SherifGhoz changed the title how to translate head tags after detecting browser language? how to translate head contents after detecting browser language? May 27, 2020
@rchl
Copy link
Collaborator

rchl commented May 27, 2020

Please create repro test case. For example on codesandbox

@SherifGhoz
Copy link
Author

Please create repro test case. For example on codesandbox

done

@rchl
Copy link
Collaborator

rchl commented May 28, 2020

Thanks. I can reproduce.

It does look like a core Nuxt issue though. I can probably manage to reproduce it without nuxt-i18n. Something to do with redirecting page early during loading.

@rchl rchl changed the title how to translate head contents after detecting browser language? Reactivity broken after redirecting from a plugin (nuxt generate) May 28, 2020
@rchl
Copy link
Collaborator

rchl commented May 28, 2020

I should be able to fix it though.

@simplenotezy
Copy link

This does not only happen with page title; it also happens in other places (e.g. the menu). See example: https://thejewelleryroom.com - try to get your locale to be "danish", you should be redirected to https://thejewelleryroom.com/da but page content is still english, and so is the menu.

@simplenotezy
Copy link

Could you recommend any workaround @rchl untill this is fixed?

@rchl
Copy link
Collaborator

rchl commented Jun 3, 2020

I'm looking into it.

rchl added a commit that referenced this issue Jun 3, 2020
When we've detected browser language and need to redirect we need to do
it from the middleware for the page to transition correctly. The problem
is Nuxt doesn't trigger middleware for initial navigation in static
mode (the idea is that it already ran when generating page on the server),
so we can't do it properly.

Fixed by hooking into the VueRouter "beforeEach" navigation hook so that
we can handle it from the right place. Still, as Nuxt doesn't know that
we are redirecting, it would throw some errors trying to load previous
page. So use "location.assign()" to "hard" redirect.

Resolves #737
rchl added a commit that referenced this issue Jun 3, 2020
When we've detected browser language and need to redirect we need to do
it from the middleware for the page to transition correctly. The problem
is Nuxt doesn't trigger middleware for initial navigation in static
mode (the idea is that it already ran when generating page on the server),
so we can't do it properly.

Fixed by hooking into the VueRouter "beforeEach" navigation hook so that
we can handle it from the right place. Still, as Nuxt doesn't know that
we are redirecting, it would throw some errors trying to load previous
page. So use "location.assign()" to "hard" redirect.

Resolves #737
rchl added a commit that referenced this issue Jun 3, 2020
When we've detected browser language and need to redirect we need to do
it from the middleware for the page to transition correctly. The problem
is Nuxt doesn't trigger middleware for initial navigation in static
mode (the idea is that it already ran when generating page on the server),
so we can't do it properly.

Fixed by hooking into the VueRouter "beforeEach" navigation hook so that
we can handle it from the right place. Still, as Nuxt doesn't know that
we are redirecting, it would throw some errors trying to load previous
page. So use "location.assign()" to "hard" redirect.

Resolves #737
rchl added a commit that referenced this issue Jun 3, 2020
When we've detected browser language and need to redirect we need to do
it from the middleware for the page to transition correctly. The problem
is Nuxt doesn't trigger middleware for initial navigation in static
mode (the idea is that it already ran when generating page on the server),
so we can't do it properly.

Fixed by hooking into the VueRouter "beforeEach" navigation hook so that
we can handle it from the right place. Still, as Nuxt doesn't know that
we are redirecting, it would throw some errors trying to load previous
page. So use "location.assign()" to "hard" redirect.

Resolves #737
@rchl
Copy link
Collaborator

rchl commented Jun 3, 2020

@simplenotezy Are you able to beta test the fix for me?

npm i nuxt-i18n@beta
or
yarn add nuxt-i18n@beta

It has some potential to change behavior as it uses location.assign() to redirect instead of using router to push the route.

Fix only affects static mode on the client and only the initial navigation.

@simplenotezy
Copy link

On it

@simplenotezy
Copy link

Seems to do the trick, see https://thejewelleryroom.com

However, I just found this bug: #717

@rchl rchl closed this as completed in #753 Jun 5, 2020
rchl added a commit that referenced this issue Jun 5, 2020
When we've detected browser language and need to redirect we need to do
it from the middleware for the page to transition correctly. The problem
is Nuxt doesn't trigger middleware for initial navigation in static
mode (the idea is that it already ran when generating page on the server),
so we can't do it properly.

Fixed by hooking into the VueRouter "beforeEach" navigation hook so that
we can handle it from the right place. Still, as Nuxt doesn't know that
we are redirecting, it would throw some errors trying to load previous
page. So use "location.assign()" to "hard" redirect.

Resolves #737
@rchl rchl reopened this Jun 5, 2020
@rchl
Copy link
Collaborator

rchl commented Aug 1, 2020

The fix was released and #717 is hopefully also addressed so closing this one.

@rchl rchl closed this as completed Aug 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants