question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Shallow routing example throws TypeError: Cannot read property 'auth' of null

See original GitHub issue

Bug report

I’m not sure this is a bug, but it throws an error and it probably shouldn’t.

Describe the bug

Shallow routing following the docs throws TypeError:

Unhandled Rejection (TypeError): Cannot read property 'auth' of null

To Reproduce

Clone repo and run:

https://github.com/tgdn/nextjs-shallow-typeerror/

Expected behavior

Error should not be thrown.

System information

  • OS: macOS
  • Version of Next.js: tried both 9.3.2 and 9.3.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
gndeliacommented, Apr 14, 2020

I came across the same problem in the docs and I found this issue, so I created a small PR to update the docs 😃

1reaction
HassenHichricommented, Apr 11, 2020

@tgdn @jamesmosier I came across the same issue while following the docs. I think the problem comes from here where as is initiated to url (typeof null return always object), and because passing null is different from undefined for the behaviour of default parameter value(see here) , as parameter doesn’t get url value when initiated to null.

@timneutkens I can see 2 possibilities here:

  • update the docs to use undefined instead of null: router.push('/?counter=10', undefined, { shallow: true })
  • add null check for as parameter in push function (maybe also in replace function), something like this in router.ts:
push(url: Url, as: Url = url, options = {}) {
    return this.change('pushState', url, as === null ? url : as, options)
  }

I would be happy to submit a PR with either of these solutions 😊

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next.js build version fails with 'Cannot read property 'auth' of ...
However as of yesterday we're suddenly getting an error on the production version when applying a router.push : Cannot read property 'url' ...
Read more >
cannot read property 'usecontext' of null nextjs - You.com
Shallow routing following the docs throws TypeError: Unhandled Rejection (TypeError): Cannot read property 'auth' of null ...
Read more >
Untitled
TypeError : Cannot read property 'getContext' of null I have created a game using ... Cannot destructure property `auth` of 'undefined' or 'null'...
Read more >
Shallow Routing - Next.js
This is due to middleware being able to rewrite dynamically and can't be verified client-side without a data fetch which is skipped with...
Read more >
Vue Router - Vue Testing Handbook
For example, if you are rendering your entire <App> component, chances are the render tree is large, containing many components with their own ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found