Skip to content

Conversation

@Rich-Harris
Copy link
Member

#17646 got me thinking: why don't we allow deriveds to reference their own values? It's unusual for it to be useful, but there are arguably valid use cases, at least now that deriveds are writable — things like this:

<script>
	var score = $state(0);
	var highscore = $derived(Math.max(score, highscore || 0));
</script>

<p>score: {score}</p>
<p>highscore: {highscore}</p>

<button onclick={() => score += 1}>score a point</button>
<button onclick={() => score = 0}>start new game</button>
<button onclick={() => score = highscore = 0}>reset</button>

That works on this branch, though one test is failing for reasons I don't really understand. Won't invest any time into figuring it out unless we decide that this does in fact make sense.

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 Feb 10, 2026

🦋 Changeset detected

Latest commit: b199f83

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Minor

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 deployed to Publish pkg.pr.new (maintainers) February 10, 2026 02:34 — with GitHub Actions Active
@github-actions
Copy link
Contributor

Playground

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

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.

1 participant