The Wayback Machine - https://web.archive.org/web/20221231162522/https://github.com/sveltejs/svelte/pull/7981
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

[fix] don't run binding init unnecessarily #7981

Merged

Conversation

dummdidumm
Copy link
Member

@dummdidumm dummdidumm commented Oct 27, 2022

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

  • 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

  • Run the tests with npm test and lint the project with npm run lint

@kyrylkov
Copy link
Contributor

kyrylkov commented Nov 7, 2022

@bluwy @Conduitry @rmunn

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}));`;
Copy link
Member

@Conduitry Conduitry Nov 9, 2022

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?

Copy link
Member Author

@dummdidumm dummdidumm Nov 9, 2022

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.

@baseballyama baseballyama merged commit 4c5469b into sveltejs:master Dec 5, 2022
22 checks passed
@dummdidumm dummdidumm deleted the no-unnecessary-binding-invalidation branch Dec 5, 2022
@moisesbites
Copy link

moisesbites commented Dec 7, 2022

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?

    "@sveltejs/adapter-node": "^1.0.0-next.102",
    "@sveltejs/kit": "^1.0.0-next.572",
    "svelte": "3.54.0",
    "svelte-check": "^2.10.1",
    "svelte-preprocess": "^4.10.7",
    "vite": "3.2.5",

@dummdidumm
Copy link
Member Author

dummdidumm commented Dec 7, 2022

Please provide a reproducible and open a new issue

@moisesbites
Copy link

moisesbites commented Dec 7, 2022

Please provide a reproducible and open a new issue

Ok.. I will prepare a example.

dummdidumm added a commit to dummdidumm/svelte that referenced this pull request Dec 15, 2022
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.
dummdidumm added a commit to dummdidumm/svelte that referenced this pull request Dec 19, 2022
Fixes sveltejs#8103 introduced through sveltejs#7981
Keeps the infinite loop from happening but reopens sveltejs#6298 and sveltejs#5689
@shirotech
Copy link

shirotech commented Dec 25, 2022

Please provide a reproducible and open a new issue

I am facing a similar issue also, not sure if it's the same, please see #8146

cc merger @baseballyama

@dummdidumm
Copy link
Member Author

dummdidumm commented Dec 25, 2022

See #8114

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.

Unexpected / uneccessary store.set calls when binding values from a store
6 participants