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: add hydrate method, make hydration treeshakeable #10497

Merged
merged 8 commits into from
Feb 17, 2024

Conversation

dummdidumm
Copy link
Member

Introduces a new hydrate method which does hydration. Refactors code so that hydration-related code is treeshaken out when not using that method.
closes #9533
part of #9827

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

Introduces a new `hydrate` method which does hydration. Refactors code so that hydration-related code is treeshaken out when not using that method.
closes #9533
part of #9827
Copy link

changeset-bot bot commented Feb 16, 2024

🦋 Changeset detected

Latest commit: c2dfc0c

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
Member

@benmccann benmccann left a comment

Choose a reason for hiding this comment

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

nice! this will be great!!

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
/** @type {Node} */
let target_node = anchor_node;
if (current_hydration_fragment !== null) {
if (hydrating) {
Copy link
Member

Choose a reason for hiding this comment

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

do we need this (and similar) guards? surely we're already only calling functions like hydrate_block_anchor when we're hydrating. rollup is smart enough to deal with it

Copy link
Member Author

Choose a reason for hiding this comment

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

Depends on the method, in this case there's no if block at the call site because it would result in more if block code overall.

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 what I was talking about last week in our call. I wasn't seeing the tree shaking working as expected by Rollup. However, if you put into this boolean guard then it works great – something I didn't do.

Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

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

mostly looks good but i have some questions, will finish reviewing soon — making sure we don't merge in the meantime

@Rich-Harris Rich-Harris merged commit 72ff536 into main Feb 17, 2024
6 of 8 checks passed
@Rich-Harris Rich-Harris deleted the treeshakeable-hydration branch February 17, 2024 16:25
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.

Improve tree-shaking for unused hydration/transition code in Svelte 5
4 participants