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

Prerendering a page that uses navigateTo results in an error #1402

Closed
tobiasdiez opened this issue Jul 6, 2023 · 4 comments · Fixed by #1448
Closed

Prerendering a page that uses navigateTo results in an error #1402

tobiasdiez opened this issue Jul 6, 2023 · 4 comments · Fixed by #1448
Labels
bug Something isn't working nuxt prerender

Comments

@tobiasdiez
Copy link
Contributor

tobiasdiez commented Jul 6, 2023

Environment

  • Operating System: Windows_NT
  • Node Version: v19.9.0
  • Nuxt Version: 3.6.2
  • Nitro Version: 2.5.2

Reproduction

Do you have a starter template for reproductions?

Describe the bug

If you use navigateTo on a (nuxt) page that is prerendered, the prerendering fails as the status code is 302 and not 200:

Prerendering 4 initial routes with crawler                        nitro 20:02:29
  ├─ ....
  ├─ /download (208ms) (Error: [302] )                               nitro 20:02:31
                                                                     nitro 20:02:31  
Errors prerendering:
  ├─ /download (302)

Additional context

This error comes from the check

nitro/src/prerender.ts

Lines 171 to 176 in 6bc50b2

if (res.status !== 200) {
_route.error = new Error(`[${res.status}] ${res.statusText}`) as any;
_route.error.statusCode = res.status;
_route.error.statusMessage = res.statusText;
erroredRoutes.add(_route);
}
.

If one adds res.status !== 302 it works well. I can open a PR with this fix, but I'm not sure if there are any negative consequences or if there is a better way to handle prerenders of redirects.

Logs

No response

@davidsandoz
Copy link

I also get the same behaviour with Nitro 2.5.2 (Nuxt 3.6.2), that I didn't get with Nitro 2.5.1 (Nuxt 3.6.1), but because of redirect in the routeRules of nuxt.config.ts

  routeRules: {
    '/': {redirect: '/search'}
  },

I get this error:

...
Generated public .output/public
Initializing prerenderer
Prerendering 3 initial routes with crawler
   ├─ / (11ms) (Error: [307] )
   ├─ /200.html (48ms)
   ├─ /404.html (48ms)
 
Errors prerendering:
   ├─ / (307)

The 307 Temporary Redirect is interpreted as an error.

I suppose that all 3xx redirection status codes could be allowed.

@MarcusAngel
Copy link

Bumping this as currently any kind of redirect in a route completely blocks pre-rendering completely

@Hebilicious
Copy link
Member

Related #1418

@pi0
Copy link
Member

pi0 commented Jul 17, 2023

Let's followup via #1418

@pi0 pi0 closed this as completed Jul 17, 2023
@pi0 pi0 added the nuxt label Jul 17, 2023
tobiasdiez added a commit to JabRef/JabRefOnline that referenced this issue Sep 16, 2023
tobiasdiez added a commit to JabRef/JabRefOnline that referenced this issue Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working nuxt prerender
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants