Skip to content

Commit

Permalink
fix: ignore warning binding non reactive (#12524)
Browse files Browse the repository at this point in the history
This prop that is bound to doesn't need to be reactive, so ignoring the warning is the best option
closes sveltejs/svelte#12514
  • Loading branch information
paoloricciuti authored Aug 1, 2024
1 parent 998edb2 commit 32220ef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-jars-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: Svelte 5 - ignore `binding_non_reactive` warning in generated root component (you also need to update to `svelte@5.0.0-next.204`)
7 changes: 6 additions & 1 deletion packages/kit/src/core/sync/write_root.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ export function write_root(manifest_data, output) {

let l = max_depth;

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

while (l--) {
pyramid = dedent`
{#if constructors[${l + 1}]}
${isSvelte5Plus() ? '<!-- svelte-ignore binding_property_non_reactive -->' : ''}
<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}}>
${pyramid}
</svelte:component>
{:else}
${isSvelte5Plus() ? '<!-- svelte-ignore binding_property_non_reactive -->' : ''}
<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}} {form} />
{/if}
`;
Expand Down
16 changes: 16 additions & 0 deletions packages/kit/test/apps/basics/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1198,3 +1198,19 @@ test.describe('INP', () => {
expect(time).toBeLessThan(400);
});
});

test.describe('binding_property_non_reactive warn', () => {
test('warning is not thrown from the root of svelte', async ({ page }) => {
let is_warning_thrown = false;
page.on('console', (m) => {
if (
m.type() === 'warn' &&
m.text().includes('binding_property_non_reactive `bind:this={components[0]}`')
) {
is_warning_thrown = true;
}
});
await page.goto('/');
expect(is_warning_thrown).toBeFalsy();
});
});

0 comments on commit 32220ef

Please sign in to comment.