Skip to content

fix: reset hydrate_node after hydrate(...) #12512

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

Merged
merged 1 commit into from
Jul 20, 2024
Merged

Conversation

Rich-Harris
Copy link
Member

While looking into #12425 (comment) I realised that hydrate inside a programmatic snippet currently fails, because we don't reset hydrate_node.

This fixes it, and also adds a test showing how to render components in programmatic snippets. (It's fine to call hydrate with an empty target — it defers immediately to mount.)

It did force a couple of realisations:

  • render(Component, {...}) fails in the client — obviously — because it tries to pass the server $$payload to the client component function that expects an $$anchor. I wonder if render should instead return a { head: '', body: '' } object if it's run in the browser? It would be convenient for this use case, though perhaps surprising for others. (In an ideal world each component would include both client and server code, and we'd somehow treeshake away the stuff we weren't using, but it's not really possible AFAICT.)
  • it might be convenient to have a svelte/environment module with dev and browser exports, just like we have in SvelteKit (and in future, it could replace $app/environment). I tried writing the test with a typeof window check, but it turns out window is defined in the Vitest environment so it didn't work, and I had to add a mechanism for adding server props to tests instead

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.

Tests and linting

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

Copy link

changeset-bot bot commented Jul 20, 2024

🦋 Changeset detected

Latest commit: a8f964c

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

@Rich-Harris Rich-Harris mentioned this pull request Jul 20, 2024
5 tasks
@Rich-Harris Rich-Harris merged commit f402d01 into main Jul 20, 2024
9 checks passed
@Rich-Harris Rich-Harris deleted the reset-hydrate-node branch July 20, 2024 21:21
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