Svelte: Cannot read property 'p' of undefined

Created on 5 Apr 2020  路  6Comments  路  Source: sveltejs/svelte

Describe the bug
If you open this REPL and click on "3", the console shows the following error:

message: "Uncaught (in promise): Cannot read property 'p' of undefined"
stack: TypeError: Cannot read property 'p' of undefined
at Object.update [as p] (eval at handle_message (about:srcdoc:13:8), <anonymous>:496:17)
at Object.update [as p] (eval at handle_message (about:srcdoc:13:8), <anonymous>:563:26)
at update (eval at handle_message (about:srcdoc:13:8), <anonymous>:161:40)
at flush (eval at handle_message (about:srcdoc:13:8), <anonymous>:130:17)

Not sure, if I am doing something wrong here. I wasn't able to debug this properly.. At least, I didn't find a similar bug report.

Thanks for any hints.

bug has pr

Most helpful comment

it is fixed in the PR
I wish you could test changes made to the compiler in the REPL though

new folder
git clone https://github.com/pushkine/svelte/tree/patch-2
npm install
npm run dev
npm link

new folder
npx degit sveltejs/template
npm link svelte
npm install
copy paste your repl components into src
npm run dev
localhost:5000

All 6 comments

There seems to be some bug here that I'm not too clear on, but your component still wouldn't work anyway, because Svelte won't know to rerun isInRange when activePage changes. Functions in the template are re-run when any of their arguments change, not when additional variables the function bring in from a higher scope are changed.

Ha! Thanks! Indeed, passing the activePage in isInRange function avoids the error.

I'd like to keep this issue open, as the error is still somewhere around. Feel free to close it anways ;)

@dritter would it be possible to create a simpler repro (with code that would eventually work) that way we might be able to debug this and find a fix?

Hi @antony ,
unfortunately I wasn't able to reproduce it with working code. But I managed to strip the example a bit down (works with a synthetic click). Interesting is that if I reduce the amount of pages to 7 or remove the class:active={currentPage === activePage} binding, the error disappears..

Btw. is there a way to easily test https://github.com/sveltejs/svelte/pull/4633 ?

it is fixed in the PR
I wish you could test changes made to the compiler in the REPL though

new folder
git clone https://github.com/pushkine/svelte/tree/patch-2
npm install
npm run dev
npm link

new folder
npx degit sveltejs/template
npm link svelte
npm install
copy paste your repl components into src
npm run dev
localhost:5000

The other issues with the example itself remain, but the bug this revealed is fixed in 3.21.0.

Was this page helpful?
0 / 5 - 0 ratings