Skip to content

fix: no infinite reload loop upon a persistent hydration error with an HTML-only error page - #3599

Closed
brillout wants to merge 1 commit into
mainfrom
claude/html-only-error-page-loop
Closed

brillout wants to merge 1 commit into
mainfrom
claude/html-only-error-page-loop

Conversation

@brillout

Copy link
Copy Markdown
Member

Split out of #3598.

If an error occurs during hydration and the error page isn't client-side routable (e.g. an HTML-only error page), Vike hard-redirects to the current URL. But the server already rendered that URL: it renders the same page again, hydration fails again, and so on. If the error persists, that's an infinite reload loop. In a repro with a client-side hook that always throws, the page was loaded 324 times within 8 seconds.

Upon hydration, Vike now leaves the server-rendered page as it is and falls back to Server Routing. Without that fallback, the next link click would wait forever for the hydration to end. The error is still logged.

Upon client-side navigation, nothing changes: Vike still redirects, so the server renders the error page. That redirect is needed: the client can't render an HTML-only error page. Without the redirect, a server error during navigation leaves a blank page (checked locally).

When this happens

Only if the error page isn't client-side routable:

  • it's HTML-only: +Page.server.js, Page with env: { client: false }, clientHooks: false, or no onRenderClient applies to it
  • or clientRouting isn't enabled for it

With vike-react/vue/solid defaults the error page is client-side routable, so this is rare.

Test

New test/error-page-html-only/ (dev and preview): a page whose client-side hook always throws, with an HTML-only error page. It fails without the fix (8 page loads instead of 1). With the fix there's one page load, and links still work.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VdMeoWMUuZtWBoUosW7ZqD


Generated by Claude Code

…n HTML-only error page

If an error occurs upon hydration and the error page isn't client-side
routable (e.g. an HTML-only error page), Vike redirects to the current
URL. But the server already rendered that URL: it renders the same page
again, the error occurs again upon hydration, and so on — an infinite
reload loop if the error persists (e.g. with a client-side hook that
always throws, the page was loaded 324 times within 8 seconds).

Upon hydration, Vike now leaves the server-side rendered page as it is
and falls back to Server Routing: the page isn't hydrated, so Client
Routing would otherwise wait forever for the hydration to end upon the
next link click. The error is still logged (by handleError()).

Upon client-side navigation, Vike still redirects so that the server
renders the error page: the client-side can't render an HTML-only error
page (without the redirect, the page would be blank).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VdMeoWMUuZtWBoUosW7ZqD

Copy link
Copy Markdown
Member Author

Closing: this only affects apps whose error page isn't client-side routable (e.g. a server-only +Page.server.js error page) combined with an error on every hydration, which is too rare to justify extra code. If someone runs into it, the fix on their side is to make the error page client-side routable.


Generated by Claude Code

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants