apal21 / nextjs-progressbar

A simple Next.js progressbar component using NProgress.
https://www.npmjs.com/package/nextjs-progressbar
MIT License
776 stars 61 forks source link

Cannot destructure `shallow` of `undefined` #106

Closed nandorojo closed 5 months ago

nandorojo commented 5 months ago
image

We're getting this after setting showOnShallow={false}. I'm guessing there is a missing null check in there.

nandorojo commented 5 months ago

https://github.com/apal21/nextjs-progressbar/blob/master/src/index.tsx#L87-L93

Here's the problem.

nandorojo commented 5 months ago

PR opened at https://github.com/apal21/nextjs-progressbar/pull/107

imranbarbhuiya commented 5 months ago

is your issue related to https://github.com/apal21/nextjs-progressbar/issues/70#issuecomment-1061533686?

nandorojo commented 5 months ago

Not sure, that comment isn’t that clear. I don’t think so. It’s just because the object containing shallow can be undefined but the handler in this library treats it as required.

nandorojo commented 5 months ago

My PR fixes it

imranbarbhuiya commented 5 months ago

according to nextjs docs, the object containing shallow will be always there so there's no need to pass a default, check https://nextjs.org/docs/pages/api-reference/functions/use-router#routerevents

The comment I link is for the same issue but it was caused by manually emitting this event. If u are manually emitting this event without the 2nd param then it'll throw. So check if the event u are receiving is coming from nextjs or emitted from your code. If it's from your code then add the shallow part in the event emit param

nandorojo commented 5 months ago

Thanks for the explanation, that's very useful to know. We are using events.emit('routeChangeError') somewhere without the second argument, so it's likely due to that. My apologies for the incorrect issue.

nandorojo commented 5 months ago

is your issue related to https://github.com/apal21/nextjs-progressbar/issues/70#issuecomment-1061533686?

Also, small thing, when I originally clicked the comment you linked to on GH mobile, it sent me to a different one higher on the page. Now that I click it on desktop it takes me to yours, which does indeed explain the issue properly. So that's my mistake.