Skip to content

fix: handle hydration mismatches in await blocks #15708

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 5 commits into from
Apr 10, 2025
Merged

fix: handle hydration mismatches in await blocks #15708

merged 5 commits into from
Apr 10, 2025

Conversation

Rich-Harris
Copy link
Member

closes #15704

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
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

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

Copy link

changeset-bot bot commented Apr 8, 2025

🦋 Changeset detected

Latest commit: dfd0c11

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

This PR includes changesets to release 1 package
Name Type
svelte Patch

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

Copy link
Contributor

github-actions bot commented Apr 8, 2025

Playground

pnpm add https://pkg.pr.new/svelte@15708

@Rican7
Copy link
Contributor

Rican7 commented Apr 8, 2025

Oh wow, this is great! Thanks Rich! I appreciate it!

I would have tried to tackle this myself, but I wasn't sure where to start. Turns out it wasn't in Kit where I reported the issue. Whoops! 😅

{#if true}<p>loading...</p>{/if}
{:then b}
<p>{b}</p>
{/await}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is interesting. I was actually finding that the runtime was only having issue when I used a Component and an if (browser) conditional in the await block, rather than "normal" HTML. I have no idea why, though, and that may have just been due to my surrounding structure.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the component is sufficient but not necessary — basically anything that adds 'structure' will confuse the hydration algorithm if there's a mismatch, and the if block does the same thing. For test cases it's handy to keep things in a single component where possible, so I always try to whittle down

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, that makes total sense. I'm just surprised this recreated the issue. Thanks for the fix!

@Rich-Harris Rich-Harris merged commit 6d195f0 into main Apr 10, 2025
13 checks passed
@Rich-Harris Rich-Harris deleted the gh-15704 branch April 10, 2025 12:19
@github-actions github-actions bot mentioned this pull request Apr 10, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conditional promise rendering breaks hydration
3 participants