Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default class InlineComponentWrapper extends Wrapper {
return;
}

const ignores = extract_ignores_above_node(this.node);
const ignores = extract_ignores_above_node(this.node);
this.renderer.component.push_ignores(ignores);
if (variable.reassigned || variable.export_name || variable.is_reactive_dependency) {
this.renderer.component.warn(this.node, compiler_warnings.reactive_component(name));
Expand Down Expand Up @@ -309,6 +309,9 @@ export default class InlineComponentWrapper extends Wrapper {
}`);
}


const is_key_block_child = this.parent && this.parent.node.type === 'KeyBlock';
const key_called = '_called';
const munged_bindings = this.node.bindings.map(binding => {
component.has_reactive_assignments = true;

Expand Down Expand Up @@ -397,7 +400,8 @@ export default class InlineComponentWrapper extends Wrapper {

component.partly_hoisted.push(body);

return b`@binding_callbacks.push(() => @bind(${this.var}, '${binding.name}', ${id}));`;
const run_call_back = is_key_block_child && x`!${block.name}.${key_called}`;
return b`@binding_callbacks.push(() => @bind(${this.var}, '${binding.name}', ${id}, ${run_call_back}));`;
});

const munged_handlers = this.node.handlers.map(handler => {
Expand Down Expand Up @@ -523,9 +527,9 @@ export default class InlineComponentWrapper extends Wrapper {
${props && b`let ${props} = ${attribute_object};`}`}
${statements}
${name} = new ${expression}(${component_opts});

${munged_bindings}
${munged_handlers}
${is_key_block_child && x`${block.name}.${key_called} = true`}
`);

if (has_css_custom_properties) {
Expand Down
6 changes: 4 additions & 2 deletions src/runtime/internal/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { children, detach, start_hydrating, end_hydrating } from './dom';
import { transition_in } from './transitions';
import { T$$ } from './types';

export function bind(component, name, callback) {
export function bind(component, name, callback, runCallback = true) {
const index = component.$$.props[name];
if (index !== undefined) {
component.$$.bound[index] = callback;
callback(component.$$.ctx[index]);
if (runCallback) {
callback(component.$$.ctx[index]);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script lang='ts'>
export let obj;
</script>

<p>
{obj.value}
</p>
4 changes: 4 additions & 0 deletions test/runtime/samples/binding-object-in-key-block/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// fix: https://github.com/sveltejs/svelte/issues/8305
export default {
html: '<p>0</p>'
};
10 changes: 10 additions & 0 deletions test/runtime/samples/binding-object-in-key-block/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
import Component from './Component.svelte';
let obj = {
value: '0'
};
</script>

{#key obj}
<Component bind:obj={obj} />
{/key}