Skip to content

Commit

Permalink
fix: sveltejs#4265 prevent double update when bind to object
Browse files Browse the repository at this point in the history
  • Loading branch information
hackape committed Jul 18, 2023
1 parent d2d219f commit 8484d92
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ export default class InlineComponentWrapper extends Wrapper {
block.maintain_context = true; // TODO put this somewhere more logical
}
block.chunks.init.push(b`
function ${id}(#value) {
${callee}(${args});
function ${id}(#value, #init_binding) {
${callee}(!!#init_binding, ${args});
}
`);
let invalidate_binding = b`
Expand All @@ -361,8 +361,10 @@ export default class InlineComponentWrapper extends Wrapper {
`;
}
const body = b`
function ${id}(${params}) {
${invalidate_binding}
function ${id}(#init_binding, ${params}) {
if (!#init_binding || ${lhs} !== #value) {
${invalidate_binding}
}
}
`;
component.partly_hoisted.push(body);
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/runtime/internal/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function bind(component, name, callback) {
const index = component.$$.props[name];
if (index !== undefined) {
component.$$.bound[index] = callback;
callback(component.$$.ctx[index]);
callback(component.$$.ctx[index], /** init_binding */ true);
}
}

Expand Down

0 comments on commit 8484d92

Please sign in to comment.