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

Uncaught Error: NotFoundError: DOM Exception 8 in {{#each}} #762

Closed
vp2177 opened this issue Aug 11, 2017 · 8 comments · Fixed by #764
Closed

Uncaught Error: NotFoundError: DOM Exception 8 in {{#each}} #762

vp2177 opened this issue Aug 11, 2017 · 8 comments · Fixed by #764
Labels

Comments

@vp2177
Copy link
Contributor

vp2177 commented Aug 11, 2017

Uncaught Error: NotFoundError: DOM Exception 8, stack trace:

image

The relevant code looks like

<div class='tbody'>
 {{#each items as item, y}}
  <div class='tr'>
    {{y}}
  </div>
 {{/each}}
</div>

items is initially [], then it's this.set({items: someArray}).

I tried to reproduce in the REPL but it works there. (Managed to repro in the REPL)

Browser: Chrome v27
Svelte: v1.29.1

Sorry I realise this bug report is not 100%, what other info would be helpful?

@Rich-Harris
Copy link
Member

This is a guess, but maybe target isn't a DOM node? This can happen if you do

import App from './App.html';

new App({
  target: document.querySelector('.does-not-exist')
});

Can happen if the selector contains a typo. Compiling with dev: true should catch this error, if that's what's happening.

@Conduitry
Copy link
Member

I was able to reproduce this on the REPL actually (Firefox, if that matters), but I don't have time right now to dig into it.

@vp2177
Copy link
Contributor Author

vp2177 commented Aug 11, 2017

In the screenshot target is visible on the right (Scope Variables), it appears to be the outer div. However node is undefined

The component itself renders fine initially, this only happens at the this.set({items}) call

@vp2177
Copy link
Contributor Author

vp2177 commented Aug 11, 2017

@Conduitry
Copy link
Member

I lied, I ended up digging into this very slightly - when a new value for items is set, we're running this code:

				for ( var i = each_block_iterations.length; i < each_block_value.length; i += 1 ) {
					each_block_iterations[i] = create_each_block( state, each_block_value, each_block_value[i], i, component );
					each_block_iterations[i].mount( div, null );
				}

We're not calling .create() on the each_block, so when we call .mount on it, we run insertNode( div, target, anchor );, and div is still undefined.

@Conduitry
Copy link
Member

Inserting a .create() call here does seem to give us the correct behavior (and none of the unit tests fail) - but I'm still not sure why this didn't come up before now, it seems like a pretty normal usage of the framework. That's the code that's been getting generated for a while. Playing with this in the REPL, it looks like like this issue arose in 1.23.0, considerably later than the above code.

@Rich-Harris
Copy link
Member

it seems like a pretty normal usage of the framework

It's slightly unusual to have an each block that doesn't use the actual data, which I suspect is why it hasn't come up already. I've put @Conduitry's fix in a PR — #764

Rich-Harris added a commit that referenced this issue Aug 13, 2017
call create() on new iterations of static each blocks
@Rich-Harris
Copy link
Member

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.

3 participants