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

next.168 development mode and component snippets inside loop #12244

Closed
vits opened this issue Jul 1, 2024 · 5 comments
Closed

next.168 development mode and component snippets inside loop #12244

vits opened this issue Jul 1, 2024 · 5 comments

Comments

@vits
Copy link

vits commented Jul 1, 2024

Describe the bug

While next.168 fixed #12233, it introduced new problem in development mode.
Component's default snippet (haven't tried named snippets) keeps previous output and appends new one if component is inside loop and array is changed, and {#each} tag has key value. It works as expected without key value and in production mode.

Reproduction

Simple component with default children snippet.

<script>
  const { children } = $props();
</script>
{@render children()}

App code

<script>
import Component from "./Component.svelte";
const sample1 = [{name: "A"}, {name: "B"}];
const sample2 = [{name: "C"}, {name: "D"}];
let items = $state(sample1);

const replace = () => {
  items = $state.is(items, sample1) ? sample2 : sample1;
}
</script>

<button onclick={replace}>replace</button>

{#each items as item (item.name)}
  <Component>
    {item.name}
  </Component>
{/each}

Logs

No response

System Info

next.168

Severity

blocking all usage of svelte

@trueadm
Copy link
Contributor

trueadm commented Jul 1, 2024

REPL

Looks to be a regression from #12215. Looking into it when we go to remove the each block entries, the anchor and end nodes are the same, even though they have content from the snippet.

Oddly the bug doesn't happen in the REPL, but does locally. So maybe it's related to the HMR bug. #12243

@vits
Copy link
Author

vits commented Jul 1, 2024

Don't know whether this is related and helps, but some problem with loops and snippets was introduced in next.162. It was different - everything worked fine in development (HMR) but was broken in production. Don't have full example, but something like this

{#each data as row (row.id)}
  <Row>
    {#each columns as column (column.name)}
      <Cell>
        {column.name}
      </Cell>
    {/each}
  </Row>
{/each}

In production this ended with empty rows after changing data array, while everything was as expected locally. This was fixed in next.167 (works as expected both locally and in production) but introduced #12233. And now in next.168 it's still fixed in production but preserves all old rows (outer loop) in HMR. Didn't try changing inner loop array (columns) though.

@Dudek-AMS
Copy link
Contributor

isnt loop or if related

#12247

@dummdidumm
Copy link
Member

For everyone experiencing this: you can disable hot module reloading through the compilerOptions.hmr setting until this is fixed.

@dummdidumm
Copy link
Member

closing as duplicate of #12243

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Jul 1, 2024
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

No branches or pull requests

4 participants