question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'splice' of undefined

See original GitHub issue

Describe the bug

I extracted a very simplified version from our code base: https://svelte.dev/repl/2a0e77c4b3e74471a51c110ecf2fcdca?version=3.35.0

I’m not sure what more to describe. Svelte crashes. Some weird edge case with nested {#each} and input[radio] I guess.

Logs

Chrome:

VM154:657 Uncaught (in promise) TypeError: Cannot read property 'splice' of undefined
    at Object.destroy [as d] (eval at handle_message (VM153 about:srcdoc:13), <anonymous>:657:80)
    at destroy_each (eval at handle_message (VM153 about:srcdoc:13), <anonymous>:48:31)
    at Object.destroy [as d] (eval at handle_message (VM153 about:srcdoc:13), <anonymous>:583:8)
    at Object.destroy [as d] (eval at handle_message (VM153 about:srcdoc:13), <anonymous>:709:17)
    at destroy_each (eval at handle_message (VM153 about:srcdoc:13), <anonymous>:48:31)
    at Object.destroy [as d] (eval at handle_message (VM153 about:srcdoc:13), <anonymous>:818:8)
    at destroy_block (eval at handle_message (VM153 about:srcdoc:13), <anonymous>:159:15)
    at update_keyed_each (eval at handle_message (VM153 about:srcdoc:13), <anonymous>:231:17)
    at Object.update [as p] (eval at handle_message (VM153 about:srcdoc:13), <anonymous>:873:23)
    at update (eval at handle_message (VM153 about:srcdoc:13), <anonymous>:146:40)

Firefox:

Uncaught (in promise) TypeError: ctx[4][0][ctx[11]][ctx[8]] is undefined
    destroy about:srcdoc line 83 > eval:657
    destroy_each about:srcdoc line 83 > eval:48
    destroy about:srcdoc line 83 > eval:583
    destroy about:srcdoc line 83 > eval:709
    destroy_each about:srcdoc line 83 > eval:48
    destroy about:srcdoc line 83 > eval:818
    destroy_block about:srcdoc line 83 > eval:159
    update_keyed_each about:srcdoc line 83 > eval:231
    update about:srcdoc line 83 > eval:873
    update about:srcdoc line 83 > eval:146
    flush about:srcdoc line 83 > eval:114
    promise callback*schedule_update about:srcdoc line 83 > eval:96
    make_dirty about:srcdoc line 83 > eval:281
    ctx about:srcdoc line 83 > eval:317
    removeOperation about:srcdoc line 83 > eval:937
    click_handler about:srcdoc line 83 > eval:947
    click_handler about:srcdoc line 83 > eval:738

To Reproduce

https://svelte.dev/repl/2a0e77c4b3e74471a51c110ecf2fcdca?version=3.35.0

Hit both “remove” buttons from top to bottom. The first element (without the radios) is important or else it doesn’t reproduce (with just a single item). See:

https://user-images.githubusercontent.com/679144/111912796-8f956b00-8a6b-11eb-9133-7784adc2d6c1.mp4

Expected behavior

No error

Information about your Svelte project:

Mostly irrelevant, since it reproduces in repl. In Chrome and Firefox for me.

  System:
    OS: Linux 5.8 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i7-6770HQ CPU @ 2.60GHz
    Memory: 5.69 GB / 15.53 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
    npm: 7.6.3 - ~/.nvm/versions/node/v14.16.0/bin/npm
  Browsers:
    Chrome: 89.0.4389.90
    Firefox: 86.0
  npmPackages:
    svelte: ^3.35.0 => 3.35.0

Severity

Since it completely crashes the script / production app this is serious I guess?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mdynnlcommented, Jan 4, 2022

This should just work and be fixed. But there are ways to workaround that.

  1. Use non-keyed each in top-level
  2. Introduce a component boundary to wrap <input bind:group />

While 1 is not an option if there are a lot of elements, 2 is pretty straightforward and easy which I think most do this already, judging this issue didn’t get crowded.

0reactions
kamholzcommented, Jan 4, 2022

Just ran into this. Would be good to get it fixed!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'splice' of undefined - json - Stack Overflow
Incorrect splice, instead use below. $scope.favgames , doesn't contain any values and is undefined. favgames.splice(index,1);. Or set,
Read more >
Uncaught TypeError: Cannot read property 'splice' of undefined
I am getting this error when trying to delete single/multi records from the table populated from JSON model. Error: Cannot read property 'splice...
Read more >
Cannot read property 'splice' of undefined · Issue #259 - GitHub
I'm getting a 'Cannot read property 'splice' of undefined' error on the line below when I try to apply the diff with a...
Read more >
Uncaught TypeError: Cannot read property 'splice' of undefined
What this error means? It occur while my data is fetching from the database to dataTable. I am using pipeling concept of dataTable....
Read more >
Getting Codemirror internal error: Cannot read property 'splice ...
This probably happens because you're passing something of the wrong value somewhere, but without a more precise location (line 396 in minified ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found