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

Compile error: Nested loops with index broke after 3.9.1 #3588

Closed
Xerios opened this issue Sep 18, 2019 · 3 comments · Fixed by #3702
Closed

Compile error: Nested loops with index broke after 3.9.1 #3588

Xerios opened this issue Sep 18, 2019 · 3 comments · Fixed by #3702
Labels

Comments

@Xerios
Copy link

Xerios commented Sep 18, 2019

Describe the bug
You can see the exact same weird parsing behavior in the example below

Logs
Generated code is wrong, for instance when using {@debug paneIndex} it generates this:
image
(paneIndex is the index from {#each ... } loop)

To Reproduce
https://svelte.dev/repl/af7ece0c29f240ad97bf795bd3be1347?version=3.9.1

  • Remove debug, it compiles properly
  • Remove the inner loop, and it compiles properly.
  • Debug is not at fault here, because in my project, the index is no longer passed onto nested loops which breaks my code.

Expected behavior

  • Proper compilation without errors

Stacktraces

  • No errors from the compiler, only compiled code gives an error

Information about your Svelte project:

  • Svelte version 3.9.1 compared to every single version above

Severity

  • Medium, project is live with over 100+ daily CCU. Having smooth animations is very important in my project. I would've loved to have latest transition/animations fixes which currently look a bit janky in 3.9.1, this compiler issue prevents me from upgrading.
@ghost
Copy link

ghost commented Sep 18, 2019

@Xerios, the code from the REPL builds and works under 3.12.1 when building for production via npm run build and npm run start so I think it really is debugging/dev codegen that is causing the issue. The if () is still the culprit, as you said, though.

@Xerios
Copy link
Author

Xerios commented Sep 19, 2019

Turns out my issue was some sort of race condition.

After diving into the generated code I noticed this:

function create_each_block$5(ctx) {
  // ctx.data has 0 elements, thus if_block is not created
  var if_block = ctx.data[ctx.paneIndex] && create_if_block_1$4(ctx);
  // ...
  const block = {
    p: function update(changed, new_ctx) {
      // ctx.data has one element, but since if_block wasn't created, it gives an error
      if (ctx.data[ctx.paneIndex]) if_block.p(changed, ctx);
    }
  }
}

@Conduitry
Copy link
Member

This bug is still present with the changes in the code-red branch, but manifests as a compile-time exception rather than outputting invalid code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants