forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat(middleware)!: forbid response body #1
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nkzawa
reviewed
May 5, 2022
feugy
force-pushed
the
feat/forbid-middleware-response-body
branch
from
May 10, 2022 12:46
cfb312c
to
cf3ac85
Compare
This aligns the output with what npm outputs. Without this change, Next.js causes unwanted changes in package-lock.json. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [x] Make sure the linting passes by running `yarn lint`
## Documentation / Examples - Updating Tina Demo URL - Adding Tina to blog-starter example - Adding Tina to Basic features section - Updating Tina to actually work again
* move FlightManifestPlugin to server compilers * revert loader condition * fix module id * fix test and refactor Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
* Update moduleNameMapper jest config and remove extra deps * move svg mock to its own entry for easier overriding * remove package script
When getInitialProps is customized with react 18, since gIP requires to return `html` as doc property which could be used by user-land customization, we do blocking-rendering there and passdown the `html` to document Fixes vercel#36675 Closes vercel#36419
Leverages Webpack builtin errors for better reporting
feugy
force-pushed
the
feat/forbid-middleware-response-body
branch
from
May 11, 2022 13:47
cf3ac85
to
26d4b06
Compare
Closing in favor of vercel#36835 |
feugy
pushed a commit
that referenced
this pull request
Dec 9, 2022
Enables `appDir` test for `deploy` in the `test/e2e/app-dir/index.test.ts` test suite.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's in there?
As part of the Edge Functions General Availability roadmap, it has been decided to only support the following uses cases in Next.js' middleware:
x-middleware-rewrite
response header)Location
response header)x-middleware-next
response header)Response
orNextResponse
).All returned/thrown errors contain a link to the documentation.
This is a breaking feature compared to the beta middleware implementation.
It also removes
NextResponse.json()
.How to try it?
The new error is covered with:
HEADLESS=true yarn jest test/integration/middleware/core
HEADLESS=true yarn jest test/integration/middleware/build-errors
HEADLESS=true yarn jest test/development/middleware-warnings
Notes to reviewers
The limitation happens in next's web adapter. The initial implementation was to check
response.body
existence, but it turns outResponse.redirect()
may return an empty stream. Hence why the proposed implementation specifically looks at response headers.Because this is a breaking change, I had to adjust several tests cases, previously returning JSON/stream/text bodies. When relevant, these middlewares are returning data using response headers.
About DevEx: relying on AST analysis to detect forbidden use cases is not as good as running the code.
Such cases are easy to detect:
But these are false-positive cases:
However, I see no good reasons to let user build an middleware with the cases above, hence why the build will fail, even if technically speaking, they are not setting the response body.