Nuxt.js: Undocumented difference between "universal" and "spa" mode when generating static site

Created on 18 Mar 2019  路  8Comments  路  Source: nuxt/nuxt.js

Version

v2.4.3

Reproduction link

https://github.com/nuxt-community/auth-module

Steps to reproduce

  1. Setup the auth demo
  2. Generate static site in "universal" mode
  3. Notice that login will not work
  4. Generate static site in "spa" mode
  5. Notice that login will work correctly now

What is expected ?

Static site behaves the same, regardless of "universal" or "spa" mode

What is actually happening?

There is a difference in the generated site when using "universal" mode vs "spa" mode.

Additional comments?

This issue was originally discovered here. We noticed that the auth module does not work in static mode. The problem was that $auth.state always returned false, even after a successful login. We later discovered that this only occurs if the static site was generated with mode set to universal in nuxt.config.js. When setting the mode to spa login worked correctly and $auth.state correctly returns the login state.

So somewhere there is a difference in the generated code for the static site. I'm not sure if this is intended behavior or a bug. If this is intended, it needs to be made clear in the documentation.

This bug report is available on Nuxt community (#c8852)
documentation stale

Most helpful comment

I think there are more differences worth documenting. For example middlewares.

Statically rendered page in

Universal Mode:

Middlewares only execute on route navigation, NOT on initial page load.

SPA Mode

Middlewares execute both, on page load and subsequent navigation

All 8 comments

Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as 馃晲Pending will not be automatically marked as stale.

Confirmed in [email protected]

Steps to reproduce

  1. Setup the auth demo
  2. Generate static site in "universal" mode
  3. Notice that login will not work
  4. Generate static site in "spa" mode
  5. Notice that login will work correctly now

Using nuxt generate in universal mode is not appreciate for _any dynamic content_ including authentication because server response is prerendered. Auth works fine in the standard universal mode using nuxt start so it would better idea using a hosting (either VPS or serverless) and running the nuxt server or using SPA mode.

@pi0 Thank you for the explanation. The problem is not that auth is not working, it's that there is just a behavioral difference between static sites generated in spa or universal mode. In my opinion this should at least get documented, because as it is right now there are people (me included) who stumble upon this and are left wondering why these two are different. I would even argue that it is counter-intuitive for the generated output to be different depending on which mode was used.

@dominikmontada Right. Actually, this should be better to documented about static generate. But it is not either limited to auth or a _bug_ from auth module. I would suggest moving this issue to the docs repo. /cc @manniL

Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as pending will not be automatically marked as stale.

-- nevermind

I think there are more differences worth documenting. For example middlewares.

Statically rendered page in

Universal Mode:

Middlewares only execute on route navigation, NOT on initial page load.

SPA Mode

Middlewares execute both, on page load and subsequent navigation

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bimohxh picture bimohxh  路  3Comments

vadimsg picture vadimsg  路  3Comments

VincentLoy picture VincentLoy  路  3Comments

maicong picture maicong  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments