Skip to content

fix: better code generation for const tags with async dependencies#17518

Merged
Rich-Harris merged 1 commit intomainfrom
fix-const-blockers
Jan 22, 2026
Merged

fix: better code generation for const tags with async dependencies#17518
Rich-Harris merged 1 commit intomainfrom
fix-const-blockers

Conversation

@Rich-Harris
Copy link
Copy Markdown
Member

Fixes a small thing I noticed while looking into #17461 — whenever you have a @const tag after an await, it injects an async thunk that runs before the declaration even if the declaration is directly above — in other words, for something like this...

{#if true}
	{@const a = await 1}
	{@const b = a + 1}

	<p>{b}</p>
{/if}

...we get this unnecessary middle promise:

var promises = $.run([
	async () => a = (await $.save($.async_derived(async () => (await $.save(1))())))(),
+	() => Promise.all([promises[0]]),
	() => b = $.derived(() => $.get(a) + 1)
]);

This PR removes it, and also gets rid of Promise.all in the case where there's only a single promise.

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
Copy Markdown

changeset-bot Bot commented Jan 22, 2026

🦋 Changeset detected

Latest commit: 4d08090

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

(I think the outer $.save is also unnecessary, but that can wait)

@github-actions
Copy link
Copy Markdown
Contributor

Playground

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

@Rich-Harris Rich-Harris merged commit f9cc2d2 into main Jan 22, 2026
18 checks passed
@Rich-Harris Rich-Harris deleted the fix-const-blockers branch January 22, 2026 21:05
@github-actions github-actions Bot mentioned this pull request Jan 22, 2026
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