-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: exclude readonly bindings from reactive state validation #12566
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
Conversation
`bind:this` etc only go upwards, and depending on the use case it's fine to connect it to a non-reactive variable
🦋 Changeset detectedLatest commit: be331d7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
Is bidirectionality the right criterion? Feels a bit weird to exclude If we want a basis on which to exclude Side-note: I thought we were already warning on non-reactive |
<script>
let online;
let innerWidth;
function printStuff() {
if (!online) alert('cant do this right now')
let size = innerWidth / ...;
createPicture(size);
print();
}
</script>
<svelte:window bind:online bind:innerWidth />Similar examples can be created for the other readonly bindings. Side note: the above currently creates a compiler warning, is that correct? I feel like it's a bit overzealous.
This PR started out as "don't warn on
|
|
Yeah but that's correct, because it doesn't need to be reactive, it would be (was! we changed this) very annoying to have a warning in this case. |
|
@dummdidumm I mean, I'd argue that it should be though. It keeps it consistent with the rest of our reactivity game. |
|
I would write the above example like this: <script>
function printStuff() {
if (!navigator.onLine) alert('cant do this right now')
let size = innerWidth / 1;
createPicture(size);
print();
}
</script>The only reason to use a binding is because you want something to be reactive. |
|
Adjusted it so it's only silencing the " |
bind:thisetc only go upwards, and depending on the use case it's fine to connect it to a non-reactive variableBefore submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.Tests and linting
pnpm testand lint the project withpnpm lint