Skip to content

fix: only create async functions in SSR output when necessary#17593

Merged
Rich-Harris merged 4 commits intomainfrom
remove-unnecessary-async
Jan 30, 2026
Merged

fix: only create async functions in SSR output when necessary#17593
Rich-Harris merged 4 commits intomainfrom
remove-unnecessary-async

Conversation

@Rich-Harris
Copy link
Member

At the moment we use async functions too liberally in SSR output — both in cases where an await is used (where it is necessary) and sometimes in cases where the template references values that aren't synchronously available (where it isn't). We also use $$renderer.child unnecessarily in these cases. Given something like this...

<script>
	await 1;
	let foo = 'bar'
</script>

<div data-foo={foo}></div>

...we generate this:

$$renderer.async([$$promises[1]], ($$renderer) => {
	$$renderer.child(async ($$renderer) => {
		$$renderer.push(`<div${$.attr('data-foo', foo)}></div>`);
	});
});

As of this PR, it looks like this instead:

$$renderer.async([$$promises[1]], ($$renderer) => {
	$$renderer.push(`<div${$.attr('data-foo', foo)}></div>`);
});

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

@changeset-bot
Copy link

changeset-bot bot commented Jan 29, 2026

🦋 Changeset detected

Latest commit: 5190b76

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 changed the title Remove unnecessary async fix: only create async functions in SSR output when necessary Jan 29, 2026
@github-actions
Copy link
Contributor

Playground

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

@Rich-Harris Rich-Harris merged commit ebe583f into main Jan 30, 2026
18 checks passed
@Rich-Harris Rich-Harris deleted the remove-unnecessary-async branch January 30, 2026 00:28
@github-actions github-actions bot mentioned this pull request Jan 30, 2026
7nik pushed a commit that referenced this pull request Jan 30, 2026
* fix: only create async functions in SSR output when necessary

* actually...

* simplify generated code a bit more

* simplify
7nik added a commit that referenced this pull request Feb 4, 2026
* fix: emit `each_key_duplicate` error in production

* fix: preserve key

* Update packages/svelte/src/internal/client/dom/blocks/each.js

Co-authored-by: Rich Harris <rich.harris@vercel.com>

* Update packages/svelte/src/internal/client/dom/blocks/each.js

Co-authored-by: Rich Harris <rich.harris@vercel.com>

* fix: ensure keys are validated

* fix silly test name

* fix: cover other case of duplicate keys

* emit error on hydration

* ensure the error is handled

* drop useless tests

* unused

* finish merge

* add lost check back

* chore: bump playwright (#17565)

* chore: bump playwright

* maybe this will help somehow?

* err whatever

* fix

* chore: allow testing in production env 2 (#17590)

* Revert "chore: allow testing in production env (#16840)"

This reverts commit ffd65e9.

* new approach

* fix: handle renderer.run rejections (#17591)

* fix: handle renderer run rejections

* add test

* changeset

* simplify

* explanatory comment

---------

Co-authored-by: Antonio Bennett <abennett@mabelslabels.com>
Co-authored-by: Rich Harris <rich.harris@vercel.com>

* fix: only create async functions in SSR output when necessary (#17593)

* fix: only create async functions in SSR output when necessary

* actually...

* simplify generated code a bit more

* simplify

* fix: merge consecutive text nodes during hydration for large text content (#17587)

* fix: merge consecutive text nodes during hydration for large text content

Fixes #17582

Browsers automatically split text nodes exceeding 65536 characters into
multiple consecutive text nodes during HTML parsing. This causes hydration
mismatches when Svelte expects a single text node.

The fix merges consecutive text nodes during hydration by:
- Detecting when the current node is a text node
- Finding all consecutive text node siblings
- Merging their content into the first text node
- Removing the extra text nodes

This restores correct hydration behavior for large text content.

* add test, fix

* fix

* fix

* changeset

---------

Co-authored-by: Miner <miner@example.com>
Co-authored-by: Rich Harris <rich.harris@vercel.com>

* Version Packages (#17585)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Revert "drop useless tests"

This reverts commit 65f77ef.

* update tests

* fix test

* we don't need to expose this function any more

* figured it out... we cant have errors during reconcile

* simplify

* tweak

* unused

* revert no-longer-needed change

* unused

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
Co-authored-by: Antonio Bennett <31296212+Antonio-Bennett@users.noreply.github.com>
Co-authored-by: Antonio Bennett <abennett@mabelslabels.com>
Co-authored-by: FORMI <239411042+Richman018@users.noreply.github.com>
Co-authored-by: Miner <miner@example.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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