EmilTholin / svelte-routing

A declarative Svelte routing library with SSR support
MIT License
2.02k stars 178 forks source link

`TypeError: Cannot read properties of undefined (reading 'default')` after upgrading to `2.2.0` #262

Closed Saibamen closed 11 months ago

Saibamen commented 11 months ago

at Router.svelte:45:28

Line 45: if (default_slot) default_slot.c();

This runtime error was introduced in svelte-routing 2.2.0.

Version 2.1.0 is OK.

Related: https://github.com/EmilTholin/svelte-routing/pull/258

krishnaTORQUE commented 11 months ago

svelte version: ?? svelte-routing version: ??

Saibamen commented 11 months ago

svelte: 4.2.2 svelte-routing 2.2.0

krishnaTORQUE commented 11 months ago

Can you please try latest version of svelte-routing?

Saibamen commented 11 months ago

This same bug in 2.5.0

krishnaTORQUE commented 11 months ago

@motzel Could you please have look, Thanks

motzel commented 11 months ago

This line in the source code is completely different. The only places where the default property is read are:

https://github.com/EmilTholin/svelte-routing/blob/2673fe7c5a76d079a879f3f3a8dd03db9183b2f3/src/Router.svelte#L52 https://github.com/EmilTholin/svelte-routing/blob/2673fe7c5a76d079a879f3f3a8dd03db9183b2f3/src/utils.js#L33 https://github.com/EmilTholin/svelte-routing/blob/2673fe7c5a76d079a879f3f3a8dd03db9183b2f3/src/utils.js#L100

and none of them were changed in my PR. My guess is that the problem is in either of the last two, because the pick() function is used in Router.svelte. But I'm not able to reproduce it, it works for me.

@Saibamen Could you prepare a minimal example in which this bug appears? Or just replace route.default in these two lines in utils.js with route?.default and please check if it works.

Saibamen commented 11 months ago

Full stacktrace (version 2.2.0):

Uncaught TypeError: Cannot read properties of undefined (reading 'default')
    at Router.svelte:45:28
    at sync (index.js:150:19)
    at index.js:173:3
    at Object.subscribe2 [as subscribe] (index.js:82:11)
    at subscribe (utils.js:139:22)
    at component_subscribe (utils.js:159:31)
    at instance3 (Router.svelte:34:28)
    at init (Component.js:135:5)
    at new Router (Router.svelte:96:54)
    at create_fragment (Navigation.svelte:17:15)

image

Saibamen commented 11 months ago

@motzel: I added ? to utils.js and Router.svelte and nothing was changed. Error and stack trace is the same

motzel commented 11 months ago

@Saibamen This is all the way impossible, because there is no other reading of default property in the whole svelte-routing code. And even more so in line 45 of Router.svelte, because there is something else there. Could you please show the full stacktrace with the error? Although some minimal example of where the error occurs would be best.

motzel commented 11 months ago

Oh, I didn't notice that you already added the full stacktrace (I'm on mobile now), sorry

motzel commented 11 months ago

@Saibamen I have prepared a minimal example of svelte-routing (based on the documentation from the readme). It uses svelte-routing@2.2.0 and svelte@4.2.2, just like your project. Could you fork it and break it in the same way as in your project?

https://github.com/motzel/svelte-routing-example

Saibamen commented 11 months ago

@motzel: Working version: https://github.com/Saibamen/svelte-routing-example/tree/2-1-0_working

image

Upgrade svelte-routing to version 2.2.0 and it will have this exception.

motzel commented 11 months ago

Thanks! I'll check it out today after work (~in 8h)