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

fixes 404 no longer returned when error with code ENOENT is thrown. #11480

Closed
wants to merge 8 commits into from

Conversation

fabb
Copy link
Contributor

@fabb fabb commented Mar 30, 2020

Restore ENOENT handling during rendering to allow returning 404 statusCodes from getInitialProps.

Fixes #11406

This PR reverts an unwanted code change done in refactoring PR #10476.

Now when throwing an error with error.code='ENOENT' in getInitialProps correctly returns a 404 statusCode in the browser again.

@ijjk
Copy link
Member

ijjk commented Mar 30, 2020

Stats from current PR

Default Server Mode
General Overall increase ⚠️
zeit/next.js canary fabb/next.js fix-404-status-code Change
buildDuration 11.6s 11.1s -445ms
nodeModulesSize 52.8 MB 52.8 MB ⚠️ +408 B
Client Bundles (main, webpack, commons)
zeit/next.js canary fabb/next.js fix-404-status-code Change
main-HASH.js gzip 6.24 kB 6.24 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..c6c1.js gzip 10.1 kB 10.1 kB
framework.HASH.js gzip 39.1 kB 39.1 kB
Overall change 56.2 kB 56.2 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary fabb/next.js fix-404-status-code Change
main-HASH.module.js gzip 4.77 kB 4.77 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.71 kB 6.71 kB
framework.HA..dule.js gzip 39.1 kB 39.1 kB
Overall change 51.4 kB 51.4 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary fabb/next.js fix-404-status-code Change
polyfills-HASH.js gzip 26.3 kB 26.3 kB
Overall change 26.3 kB 26.3 kB
Client Pages
zeit/next.js canary fabb/next.js fix-404-status-code Change
_app.js gzip 1.24 kB 1.24 kB
_error.js gzip 3.15 kB 3.15 kB
hooks.js gzip 664 B 664 B
index.js gzip 222 B 222 B
link.js gzip 2.03 kB 2.03 kB
routerDirect.js gzip 279 B 279 B
withRouter.js gzip 278 B 278 B
Overall change 7.86 kB 7.86 kB
Client Pages Modern
zeit/next.js canary fabb/next.js fix-404-status-code Change
_app.module.js gzip 594 B 594 B
_error.module.js gzip 2.08 kB 2.08 kB
hooks.module.js gzip 370 B 370 B
index.module.js gzip 212 B 212 B
link.module.js gzip 1.48 kB 1.48 kB
routerDirect..dule.js gzip 271 B 271 B
withRouter.m..dule.js gzip 270 B 270 B
Overall change 5.28 kB 5.28 kB
Client Build Manifests
zeit/next.js canary fabb/next.js fix-404-status-code Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes
zeit/next.js canary fabb/next.js fix-404-status-code Change
index.html gzip 917 B 917 B
link.html gzip 925 B 925 B
withRouter.html gzip 915 B 915 B
Overall change 2.76 kB 2.76 kB

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
zeit/next.js canary fabb/next.js fix-404-status-code Change
buildDuration 12s 12.3s ⚠️ +314ms
nodeModulesSize 52.8 MB 52.8 MB ⚠️ +408 B
Client Bundles (main, webpack, commons)
zeit/next.js canary fabb/next.js fix-404-status-code Change
main-HASH.js gzip 6.24 kB 6.24 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..c6c1.js gzip 10.1 kB 10.1 kB
framework.HASH.js gzip 39.1 kB 39.1 kB
Overall change 56.2 kB 56.2 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary fabb/next.js fix-404-status-code Change
main-HASH.module.js gzip 4.77 kB 4.77 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.71 kB 6.71 kB
framework.HA..dule.js gzip 39.1 kB 39.1 kB
Overall change 51.4 kB 51.4 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary fabb/next.js fix-404-status-code Change
polyfills-HASH.js gzip 26.3 kB 26.3 kB
Overall change 26.3 kB 26.3 kB
Client Pages
zeit/next.js canary fabb/next.js fix-404-status-code Change
_app.js gzip 1.24 kB 1.24 kB
_error.js gzip 3.15 kB 3.15 kB
hooks.js gzip 664 B 664 B
index.js gzip 222 B 222 B
link.js gzip 2.03 kB 2.03 kB
routerDirect.js gzip 279 B 279 B
withRouter.js gzip 278 B 278 B
Overall change 7.86 kB 7.86 kB
Client Pages Modern
zeit/next.js canary fabb/next.js fix-404-status-code Change
_app.module.js gzip 594 B 594 B
_error.module.js gzip 2.08 kB 2.08 kB
hooks.module.js gzip 370 B 370 B
index.module.js gzip 212 B 212 B
link.module.js gzip 1.48 kB 1.48 kB
routerDirect..dule.js gzip 271 B 271 B
withRouter.m..dule.js gzip 270 B 270 B
Overall change 5.28 kB 5.28 kB
Client Build Manifests
zeit/next.js canary fabb/next.js fix-404-status-code Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles Overall increase ⚠️
zeit/next.js canary fabb/next.js fix-404-status-code Change
_error.js gzip 294 kB 294 kB -196 B
404.html gzip 1.32 kB 1.32 kB
hooks.html gzip 958 B 958 B
index.js gzip 293 kB 294 kB ⚠️ +497 B
link.js gzip 301 kB 302 kB ⚠️ +376 B
routerDirect.js gzip 301 kB 300 kB -178 B
withRouter.js gzip 300 kB 300 kB ⚠️ +140 B
Overall change 1.49 MB 1.49 MB ⚠️ +639 B

Copy link
Member

@Timer Timer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior needs a test before we can land this. In addition, it should not work for getServerSideProps.

Just to be clear: we do not suggest apps use this. You are relying on an undocumented and unintentional behavior, and this was never meant to be used like this. It's being added for backwards compatibility because it seems a lot of apps found and started using this.

@fabb
Copy link
Contributor Author

fabb commented Apr 6, 2020

I migrated away from using this hack as I described in the linked issue. I‘ll keep this open still because others might still use this hack and not have the resources for refactoring.

@ijjk ijjk requested a review from Timer April 6, 2020 17:08
Copy link
Member

@Timer Timer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a test to check that this does not work for getServerSideProps. Also, this should warn the user that relying on the behavior is wrong and can change at any time.

@Timer Timer requested a review from ijjk April 9, 2020 14:14
@ijjk
Copy link
Member

ijjk commented Apr 9, 2020

Added a warning when an error is thrown with ENOENT to trigger the 404 and added test for the warning, also made sure to copy the existing test for this from getServerSideProps to the prerender suite to ensure it's handled there also

https://github.com/zeit/next.js/blob/13cf97055ff509826be6d21f66424ae9d5c3c21f/test/integration/getserversideprops/test/index.test.js#L214-L225

@ijjk ijjk requested a review from Timer April 9, 2020 17:23
@ijjk ijjk requested a review from timneutkens April 10, 2020 15:36
@timneutkens
Copy link
Member

Looking at the issue and this PR it seems that there were only a few people that relied on these internals and adding extra checks is not warranted.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot return a 404 from getInitialProps anymore by throwing an error with code='ENOENT'
4 participants