Skip to content

Commit 32220ef

Browse files
fix: ignore warning binding non reactive (#12524)
This prop that is bound to doesn't need to be reactive, so ignoring the warning is the best option closes sveltejs/svelte#12514
1 parent 998edb2 commit 32220ef

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

.changeset/gorgeous-jars-sparkle.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: Svelte 5 - ignore `binding_non_reactive` warning in generated root component (you also need to update to `svelte@5.0.0-next.204`)

packages/kit/src/core/sync/write_root.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@ export function write_root(manifest_data, output) {
2121

2222
let l = max_depth;
2323

24-
let pyramid = `<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}} {form} />`;
24+
let pyramid = dedent`
25+
${isSvelte5Plus() ? '<!-- svelte-ignore binding_property_non_reactive -->' : ''}
26+
<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}} {form} />
27+
`;
2528

2629
while (l--) {
2730
pyramid = dedent`
2831
{#if constructors[${l + 1}]}
32+
${isSvelte5Plus() ? '<!-- svelte-ignore binding_property_non_reactive -->' : ''}
2933
<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}}>
3034
${pyramid}
3135
</svelte:component>
3236
{:else}
37+
${isSvelte5Plus() ? '<!-- svelte-ignore binding_property_non_reactive -->' : ''}
3338
<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}} {form} />
3439
{/if}
3540
`;

packages/kit/test/apps/basics/test/client.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -1198,3 +1198,19 @@ test.describe('INP', () => {
11981198
expect(time).toBeLessThan(400);
11991199
});
12001200
});
1201+
1202+
test.describe('binding_property_non_reactive warn', () => {
1203+
test('warning is not thrown from the root of svelte', async ({ page }) => {
1204+
let is_warning_thrown = false;
1205+
page.on('console', (m) => {
1206+
if (
1207+
m.type() === 'warn' &&
1208+
m.text().includes('binding_property_non_reactive `bind:this={components[0]}`')
1209+
) {
1210+
is_warning_thrown = true;
1211+
}
1212+
});
1213+
await page.goto('/');
1214+
expect(is_warning_thrown).toBeFalsy();
1215+
});
1216+
});

0 commit comments

Comments
 (0)