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: more efficient template effect grouping #15050

Merged
merged 22 commits into from
Jan 18, 2025
Merged

Conversation

Rich-Harris
Copy link
Member

@Rich-Harris Rich-Harris commented Jan 18, 2025

This simplifies the compiler code around template effects and makes the output more readable and concise. Currently we often generate a bunch of template effects per fragment, when in almost all cases we need zero or one.

It also deduplicates repeated expressions, since there's no point running a pure function twice in the same moment.

A handful of tests needed to be updated because this changes the render order in a way that doesn't matter (i.e. text nodes and attributes in a given fragment are always updated at the end, even if they come before children in the DOM).

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 Jan 18, 2025

🦋 Changeset detected

Latest commit: 34ad652

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
Copy link
Member Author

preview: https://svelte-dev-git-preview-svelte-15050-svelte.vercel.app/

this is an automated message

Copy link
Contributor

Playground

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

@Rich-Harris Rich-Harris marked this pull request as ready for review January 18, 2025 02:33
'1: $effect.pre 0',
'1: render 0',
'2: $effect.pre 0',
'2: render 0',
'3: $effect.pre 0',
'3: render 0',
'parent: render 0',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the parent template now happening before all the children templates?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's the opposite. Previously you could have multiple template effects in the root fragment, and the {logRender()} call happened before rendering the child. Now, there's just one template effect, at the end (after rendering child blocks and components etc). I don't consider this a breaking change since we're already grouping some effects at the end without giving you any control over it, and since template effects should be pure it's effectively not observable

Copy link
Contributor

@trueadm trueadm left a comment

Choose a reason for hiding this comment

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

LGTM

@Rich-Harris Rich-Harris merged commit 700029b into main Jan 18, 2025
11 checks passed
@Rich-Harris Rich-Harris deleted the group-template-effects branch January 18, 2025 15:26
@github-actions github-actions bot mentioned this pull request Jan 18, 2025
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