chore: simplify props by Rich-Harris · Pull Request #16270 · sveltejs/svelte · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

chore: simplify props #16270

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

Merged
merged 13 commits into from
Jul 1, 2025
Merged

chore: simplify props #16270

merged 13 commits into from
Jul 1, 2025

Conversation

Rich-Harris
Copy link
Member

While looking into #16263 I realised that we can drastically simplify the prop implementation now that deriveds are writable. Some of the code in red is pretty hard to understand, but deleting it causes no tests to fail. Just to be safe, I added a changeset so that this creates a new version that we can roll back from if it causes any issues.

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 Jul 1, 2025

🦋 Changeset detected

Latest commit: 0ef587a

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

@svelte-docs-bot
Copy link

Copy link
Contributor

github-actions bot commented Jul 1, 2025

Playground

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

}

return value;
}

if (has_destroyed_component_ctx(current_value)) {
return current_value.v;
// TODO is this still necessary post-#16263?
Copy link
Member

Choose a reason for hiding this comment

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

Pretty sure yes because things not read in a teardown can still cause bugs as seen in #16072 - we might need to make props signals after all, gonna investigate that soon

Comment on lines +357 to +358
// prop is written to, but there's no binding, which means we
// create a derived that we can write to locally
Copy link
Member

@dummdidumm dummdidumm Jul 1, 2025

Choose a reason for hiding this comment

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

Found it strange that the "in Svelte 4 ..." logic above in the getter was removed - did some digging and turns out that #11577 was added back when we did return the getter above in legacy mode too. Now that logic is obsolete, but we should add a comment here explaining why we need it in legacy mode, too

Suggested change
// prop is written to, but there's no binding, which means we
// create a derived that we can write to locally
// Either prop is written to, but there's no binding, which means we
// create a derived that we can write to locally.
// Or we are in legacy mode where we always create a derived to replicate that
// Svelte 4 did not trigger updates when a primitive value was updated to the same value.

Copy link
Member Author

Choose a reason for hiding this comment

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

Turns out we actually don't need the runes/legacy check when the prop isn't written to — 3933328

Copy link
Member

Choose a reason for hiding this comment

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

We do need it, the test hides the bug because it's using accessors by default. PR with fix incoming

Copy link
Member

Choose a reason for hiding this comment

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

@Rich-Harris Rich-Harris merged commit 11ec907 into main Jul 1, 2025
14 checks passed
@Rich-Harris Rich-Harris deleted the simpler-props branch July 1, 2025 18:20
@github-actions github-actions bot mentioned this pull request Jul 1, 2025
dummdidumm added a commit that referenced this pull request Jul 1, 2025
#16270 removed a condition which seemed to keep passing the corresponding test, but it actually introduced a regression since the PROPS_IS_UPDATED is always set when accessors should be created, which is the case by default in legacy mode tests. Setting accessors to false in the test reveals the regression, so this reverts that part of the refactoring
Rich-Harris pushed a commit that referenced this pull request Jul 1, 2025
#16270 removed a condition which seemed to keep passing the corresponding test, but it actually introduced a regression since the PROPS_IS_UPDATED is always set when accessors should be created, which is the case by default in legacy mode tests. Setting accessors to false in the test reveals the regression, so this reverts that part of the refactoring
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

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.