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

fix: head duplication when binding is present #9124

Merged
merged 5 commits into from
Aug 28, 2023

Conversation

gtm-nayan
Copy link
Contributor

@gtm-nayan gtm-nayan commented Aug 20, 2023

fixes #7879
fixes #4982

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

@changeset-bot
Copy link

changeset-bot bot commented Aug 20, 2023

🦋 Changeset detected

Latest commit: adea603

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


do {
$$settled = true;
// $$result.head is mutated by the literal expression
// need to reset it if we're looping back to prevent duplication
$$result.head = #previous_head;
Copy link
Member

Choose a reason for hiding this comment

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

Still don't fully understand the fix - how is the binding mutating the head?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Binding doesn't mutate it, but the emitted code is like

`${($$result.head += 'head contents', '')} body contents`

so if the loop isn't settled in one go, the next iteration will add the head contents again and so on

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see - I guess it makes sense then to only use the first head. Can there ever be a situation where this would prevent other head elements from showing up? Like, if there's some component inside an if block that contains a head element, will that be part of the first loop already?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fine, the child component inside the if will get reexecuted after resetting the head

Copy link
Member

Choose a reason for hiding this comment

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

So what constitutes to a rerun then? Only bindings? TBH I never looked into that part of the code base much. I just want to rule out that we don't lose head content that would otherwise be rightfully added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

const main = renderer.has_bindings

Looks like it's only bindings

@dummdidumm dummdidumm merged commit d5839ef into master Aug 28, 2023
7 checks passed
@dummdidumm dummdidumm deleted the fix-binding-head-duplicate branch August 28, 2023 16:53
@github-actions github-actions bot mentioned this pull request Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants