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

feat: allow to control behavior on hydration error #13521

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dummdidumm
Copy link
Member

closes #13519

This adds a new option to the SvelteKit router that allows you to control how to react when a page doesn't successfully hydrate. You can choose to keep it as is today (show root error page; the default) or keep the HTML around (the new option).

Name is subject to bikeshedding and I'm pretty sure there are better names. Also haven't talked to other maintainers yet if this is a generally good direction (but I think it's a pragmatic solution to the real world of flaky internet connections).

For now it only handles the part when loading the JS/data prior to the "hydrate the components", might be worthwhile to investigate that other part in the future as well.

Also needs tests.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Copy link

changeset-bot bot commented Feb 28, 2025

🦋 Changeset detected

Latest commit: b7884d3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot
Copy link

@itssumitrai
Copy link

This is awesome, thanks for the quick fix @dummdidumm 🙏

Comment on lines +2590 to +2591
return;
} else {
Copy link

@itssumitrai itssumitrai Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: since we return here, we don't need the else here

@eltigerchino eltigerchino added the feature / enhancement New feature or request label Mar 3, 2025
@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github added the needs-decision Not sure if we want to do this yet, also design work needed label Mar 4, 2025
@itssumitrai
Copy link

itssumitrai commented Mar 4, 2025

Hi, do we have an ETA for this fix to land, I know I am kind of rushing this but this has been a constant pain point for a lot of users and we are getting a lot of pressure now to get this fixed. The only other way to fix this currently is to patch kit on our end. Thanks 🙏

route
});
if (__SVELTEKIT_NO_ROOT_ERROR_ON_HYDRATION__) {
errored_on_hydration = true;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will the client know that this has happened and the page is not hydrated?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point. We probably also want the await handle_error(error, { url, params, route }) call as before so that normal error reporting if any does work for this error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request needs-decision Not sure if we want to do this yet, also design work needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

asset load failure results in entire page broken
5 participants