Skip to content

fix: more accurate default value handling#11183

Merged
Rich-Harris merged 1 commit into
mainfrom
destructuring-default-values
Apr 16, 2024
Merged

fix: more accurate default value handling#11183
Rich-Harris merged 1 commit into
mainfrom
destructuring-default-values

Conversation

@dummdidumm

Copy link
Copy Markdown
Member
  • don't call fallback values eagerly, only when it's actually needed. Avoids potential unwanted side effects
  • use derived_safe_equals to memoize results of destructured snippet/each context values with default values to ensure they're only recalculated when their dependencies change. Avoids unstable default values getting called multiple times yielding different results. Use derived_safe_equals to ensure new values are always set, even when mutated. fixes Svelte 5: A snippet default value is inconsistent #11143

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.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

- don't call fallback values eagerly, only when it's actually needed. Avoids potential unwanted side effects
- use derived_safe_equals to memoize results of destructured snippet/each context values with default values to ensure they're only recalculated when their dependencies change. Avoids unstable default values getting called multiple times yielding different results. Use derived_safe_equals to ensure new values are always set, even when mutated. fixes #11143
@changeset-bot

changeset-bot Bot commented Apr 15, 2024

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7511b16

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 merged commit cd7c3fe into main Apr 16, 2024
@Rich-Harris
Rich-Harris deleted the destructuring-default-values branch April 16, 2024 02:30
dummdidumm added a commit that referenced this pull request Apr 16, 2024
leftover from earlier iterations of #11183
@dummdidumm dummdidumm mentioned this pull request Apr 16, 2024
5 tasks
dummdidumm added a commit that referenced this pull request Apr 16, 2024
leftover from earlier iterations of #11183
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.

Svelte 5: A snippet default value is inconsistent

2 participants