Skip to content

feat: omit trailing $.sibling calls where possible #12932

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

Closed
wants to merge 4 commits into from

Conversation

Rich-Harris
Copy link
Member

Given this input...

<div>
  <p>{dynamic}</p>
  <p>static</p>
</div>

...we generate this output:

export default function App($$anchor) {
  var div = root();
  var p = $.child(div);

  p.textContent = dynamic;
  $.sibling(p, 2);
  $.reset(div);
  $.append($$anchor, div);
}

The $.sibling(p, 2) call exists to preserve hydration state — if the container was an {#if true} block rather than a <div>, we would need to advance hydrate_node by 2 otherwise the next thing would try and hydrate the wrong nodes.

When there is a container element, we typically call $.reset(div) instead, meaning we don't actually need the $.sibling(...) call.

This does cause an issue with the hydration mismatch detection added in #12755, however (hence the test failures). Not sure what the most elegant solution would be.

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 Aug 20, 2024

🦋 Changeset detected

Latest commit: 2b30aff

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

@trueadm
Copy link
Contributor

trueadm commented Aug 20, 2024

Can't we wrap the $.sibling(p, 2); in a hydrating flag if we know it's identifier is never referenced so at least in the cases where we aren't hydrating we don't traverse all those nodes? We could probably group multiple traversal nodes together in a side if statement too.

@Rich-Harris
Copy link
Member Author

We used to have a $.next() call that served a very similar purpose (it advanced hydrate_node and did nothing during mount). Can modify that for this case.

We could probably group multiple traversal nodes together in a side if statement

Not sure what this means?

@Rich-Harris
Copy link
Member Author

closing for now, can revisit later if nec

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