canjs / can-util

Essential utilities used by lots of CanJS's projects.
https://canjs.com/doc/can-util.html
MIT License
10 stars 8 forks source link

this.removeChild(child) in removeChild fails in nested switches #404

Open BairDev opened 6 years ago

BairDev commented 6 years ago

I'm not sure, whether this the right repo for this issue, but the problem always ends up here.

Edit This is the method in question in mutate.js.

Suppose you have at least two nested switch statements in a .stache file (like {{#switch}}). If you somehow - usually by some kind of user input - switch between the cases of the nested, inner switch, the DOM gets mutated. But if the user then - again by clicking somewhere or so - switches between the cases of the outer switch, removeChild fails, because some DOM nodes of the inner switch are not anymore children of the outer switch.

The problem usually starts with a line like canBatch.stop();, e.g. in can-route, but this stop can also be called elsewhere, like in the fiddle below.

My current workaround is to wrap the inner switch in a <div>. The inner switch can also be an {{#if}}...{{else}}...{{/if}} by the way.

Here is the demonstrating fiddle. Steps for reproducing the issue:

  1. hit F12
  2. click on radio button for first3
  3. click on radio button for second2 or second3
  4. click on radio button for first1 or first2

--> results: some text of the inner switch stays on the page and an error like this appears in the console: 'NotFoundError: Node was not found'. The error message depends on the context and probably on the browser.