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: array proxy coercion is no longer reactive in template #13538

Closed
wants to merge 4 commits into from

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Oct 9, 2024

Fixes #13525. An alternative approach to #13541.

Note: this only applies to template effects

This is an interesting one but one I think we need. When you have an object in the template, we push people to use toString() in order for its contents to be reactive – as this shows intent. Today, we have some cases where this is not consistent.

However, we have Symbol.toPrimitive and we can detect this on our proxied arrays and actually intervene and provide a non-reactive result in the case where someone hasn't explicitly called toString() from within the template. This means that we now have better consistency and we can push people to using thing.toString() instead of using coercion. Which are all far better than just having it magically be reactive with coercion.

Copy link

changeset-bot bot commented Oct 9, 2024

🦋 Changeset detected

Latest commit: 3d983fb

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

@trueadm trueadm changed the title breaking: array proxy toPrimitive is no longer reactive breaking: array proxy coercion is no longer reactive in template Oct 9, 2024
@dummdidumm
Copy link
Member

Since this only applies to template effects and not deriveds (i.e. $derived('hello '+ array) will still be reactive), should we use a special set-text function for this instead which untracks things? might result in less code and one less flag to worry about.

@trueadm
Copy link
Contributor Author

trueadm commented Oct 9, 2024

Since this only applies to template effects and not deriveds (i.e. $derived('hello '+ array) will still be reactive), should we use a special set-text function for this instead which untracks things? might result in less code and one less flag to worry about.

How would that work? Today we pass in a template literal, are you suggesting we don't use template literals anymore? Actually that's pretty interesting, let me play with that idea more.

@dummdidumm
Copy link
Member

I haven't had any concrete thoughts in mind beyond "maybe there's some way", but it seems you now have, so that's cool 😄

@trueadm trueadm closed this Oct 9, 2024
@trueadm trueadm deleted the non-reactive-toPrimitive branch November 6, 2024 15:01
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.

[Svelte5] Object are not always reactive on template
2 participants