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
[fix] don't run binding init unnecessarily #7981
[fix] don't run binding init unnecessarily #7981
Conversation
Fixes part of sveltejs#7032 Fixes sveltejs#6298
This fixes our issues described in #7032 Can this be merged ASAP and released as v3.52.1 ? |
@@ -393,7 +393,7 @@ export default class InlineComponentWrapper extends Wrapper { | |||
|
|||
component.partly_hoisted.push(body); | |||
|
|||
return b`@binding_callbacks.push(() => @bind(${this.var}, '${binding.name}', ${id}));`; | |||
return b`@binding_callbacks.push(() => @bind(${this.var}, '${binding.name}', ${id}, ${snippet}));`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In what sorts of situations will ${snippet}
be an expression that is undefined
vs non-undefined
? Is this just an approximation of whether it's the first call or not, and we're accepting that ${snippet|
might be undefined
some other times, at which point we'll call callback
when ideally we wouldn't have to? Or is something else going on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
<script>
let foo = "bar";
</script>
<SomeConponent bind:foo />
snippet
is the value of foo
, so it's defined in this case as bar
, and would be undefined
if foo
wasn't initialized, at which point we want to assign foo
to the value that foo
has inside SomeComponent
.
I don't know why it worked before having the correct value for foo
(being bar
, not the value of foo
inside SomeComponent
), but having this check breaks the infinite loop in the related issues.
Hello Guys, This update, I think, broke my code. Neither variables are updated by components by binding, nor events are fired outside the component (in svelte.kit on the +page.svelte or another component), at the first time the code is executed in the external component. Worse, not even when a {%key} is updated. My app runs on svelte.kit. How can I fix that?
|
Please provide a reproducible and open a new issue |
Ok.. I will prepare a example. |
Fixes sveltejs#8103 introduced through sveltejs#7981 while keeping the referenced bug in that PR fixed. This expands the "are the values equal"-check from just member expressions (bind:foo={member.expression}) to all occasions, because in loop scenarios the ctx object is temporarily lagging behind when doing the $$invalidate call.
Fixes sveltejs#8103 introduced through sveltejs#7981 Keeps the infinite loop from happening but reopens sveltejs#6298 and sveltejs#5689
I am facing a similar issue also, not sure if it's the same, please see #8146 cc merger @baseballyama |
See #8114 |
Fixes part of #7032
Fixes #6298
I'm honestly not sure how this didn't cause a "variable defined in parent component gets set to undefined by child" bug previously - does this hint at a deeper problem?
While testing I noticed another infinite loop, which happens when I add
<div bind:this={row.div}>foo</div>
to the each loop in this reproducible. The problem is the bind this binding invalidating the component, causing another flush, causing another each-loop traversal, causing another binding invalidation, etc. I don't know how to fix this right now so I left that out.Before submitting the PR, please make sure you do the following
[feat]
,[fix]
,[chore]
, or[docs]
.Tests
npm test
and lint the project withnpm run lint