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

Errors thrown in getServerSideProps result in full page reload without respecting the second argument in router.push #40845

Closed
1 task done
ghost opened this issue Sep 23, 2022 · 3 comments
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity.

Comments

@ghost
Copy link

ghost commented Sep 23, 2022

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

not relevant

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

When using the second argument of router.push('/page', '/displayedUrl'), you will navigate to the page 'page', but the browser shows '/displayedUrl'.

When page has a getServerSideProps handler and this handler results in an error being thrown, this causes the next client to do a full page reload to /displayedUrl instead of /page. This will typically result in a 404 page (since /displayedUrl doesn't really exist), rather than an actual reload of page (which isn't really possible, since it isn't routable at all by visiting a URL.

Expected Behavior

An improved behaviour should detect if the 'browser URL' matches the page (i.e. if the second argument of route.push was used.

If there is no match, a refresh does not make sense and a better default would be to immediately navigate to the error page.

Alternatively make getServerSideProps errors configurable/catchable from the client side.

Link to reproduction

https://github.com/TomKlaverAH/nextjs-issue-example

To Reproduce

See changes from commit https://github.com/TomKlaverAH/nextjs-issue-example/commit/a36ca42cb14641c30a2a37e52c915b2e6dcec09a

If you run the server yarn dev and click the button, you will be shown a 404 page like described above.

@ghost ghost added the bug Issue was opened via the bug report template. label Sep 23, 2022
@ghost ghost changed the title Errors thrown in getServerSideProps result in full page reload which is a problem when using the second argument in router.to Errors thrown in getServerSideProps result in full page reload which is a problem when using the second argument in router.push Sep 23, 2022
@ghost ghost changed the title Errors thrown in getServerSideProps result in full page reload which is a problem when using the second argument in router.push Errors thrown in getServerSideProps result in full page reload without respecting the second argument in router.push Sep 23, 2022
@ghost
Copy link
Author

ghost commented Sep 23, 2022

A workaround that we are currently using involves wrapping all getServerSideProps handlers in try..catch and on catch, manually logging the error and returning a redirect to the error page.

@vercel-release-bot
Copy link
Collaborator

This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.

@vercel-release-bot vercel-release-bot added the stale The issue has not seen recent activity. label Jan 10, 2025
@nextjs-bot
Copy link
Collaborator

This issue has been automatically closed due to two years of inactivity. If you’re still experiencing a similar problem or have additional details to share, please open a new issue following our current issue template. Your updated report helps us investigate and address concerns more efficiently. Thank you for your understanding!

@nextjs-bot nextjs-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity.
Projects
None yet
Development

No branches or pull requests

2 participants