Skip to content
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

breaking: change $state.frozen -> $state.raw #12511

Closed
wants to merge 1 commit into from
Closed

Conversation

Rich-Harris
Copy link
Member

closes #12434. This replaces $state.frozen with $state.raw, which no longer adds STATE_FROZEN_SYMBOL or uses Object.freeze — it leaves its argument untouched, and just creates a source for it.

Draft because one test, around each block updates, is currently failing. This is because each blocks use STATE_FROZEN_SYMBOL to determine what kind of optimisations to apply.

I'd like to explore whether there are alternative ways to think about this. I'm not a huge fan of the runtime checking anyway — it only works in simple cases (each numbers, but not each numbers.filter(is_even), etc). I think it's possible that we could get further with the compiler (though there might be some tricky caveats about props crossing runes/non-runes boundaries and so on) — for example we could definitely improve cases like this:

{#each [1, 2, 3] as n}
  <p>{n}</p>
{/each}
-$.each(node, 1, () => [1, 2, 3], $.index, ($$anchor, n, $$index) => {
+$.each(node, 1, () => [1, 2, 3], $.index, ($$anchor, n) => {
  var p = root_1();
  var text = $.child(p);

  $.reset(p);
-  $.template_effect(() => $.set_text(text, $.unwrap(n)));
+  $.set_text(text, n);
  $.append($$anchor, p);
});

Will likely investigate these ideas in other PRs and circle back to this one.

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

Copy link

changeset-bot bot commented Jul 20, 2024

⚠️ No Changeset found

Latest commit: 9612f95

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Rich-Harris
Copy link
Member Author

merge conflicts are out of control — closing in favour of #12742

@Rich-Harris Rich-Harris closed this Aug 5, 2024
@Conduitry Conduitry deleted the state-raw branch August 15, 2024 10:14
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: decide on behaviour of $state.frozen
1 participant