-
Notifications
You must be signed in to change notification settings - Fork 27.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Revert the revert in #66049 It was erroring in pages api with importing `react-dom/server` as this is disallowed in app but shouldn't be in pages. It's caused by we're validating middleware layer as server components but edge pages api is still bundled in the same layer, where we shouldn't apply the check. * Separate the api in api layers, and while handling middleware warnings, checking api layer as well * No need to check layers while handling externals in edge compiler * Found a bug that we shouldn't check if `config.transpilePackages` is defined then we enable `externalDir`, removed that condition. It fails the telemetry tests case build with code change from this PR. Add more tests for pages dir and middleware | | `react` condition | `react-dom/server` condition | | ---- | ---- | ---- | | middleware (edge) | react-server | not allowed, failed with dev/build checks | | pages/api edge | default condition | default condition | | pages/api node | default condition | default condition |
- Loading branch information
Showing
14 changed files
with
151 additions
and
55 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
import 'server-only' | ||
import React from 'react' | ||
import * as React from 'react' | ||
import { NextResponse } from 'next/server' | ||
// import './lib/mixed-lib' | ||
|
||
export function middleware(request) { | ||
if (React.useState) { | ||
// To avoid webpack ESM exports checking warning | ||
const ReactObject = Object(React) | ||
if (ReactObject.useState) { | ||
throw new Error('React.useState should not be defined in server layer') | ||
} | ||
|
||
if (request.nextUrl.pathname === '/react-version') { | ||
return Response.json({ | ||
React: Object.keys(ReactObject), | ||
}) | ||
} | ||
|
||
return NextResponse.next() | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as ReactDomServer from 'react-dom/server' | ||
import * as React from 'react' | ||
|
||
export default async (_req) => { | ||
return Response.json({ | ||
React: Object.keys(Object(React)), | ||
ReactDomServer: Object.keys(Object(ReactDomServer)), | ||
}) | ||
} | ||
|
||
export const runtime = 'edge' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as ReactDomServer from 'react-dom/server' | ||
import * as React from 'react' | ||
|
||
export default async (_req, res) => { | ||
return res.json({ | ||
React: Object.keys(Object(React)), | ||
ReactDomServer: Object.keys(Object(ReactDomServer)), | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'server-only' | ||
import * as ReactDomServer from 'react-dom/server' | ||
import * as React from 'react' | ||
|
||
export default async (_req) => { | ||
return Response.json({ | ||
React: Object.keys(Object(React)), | ||
ReactDomServer: Object.keys(Object(ReactDomServer)), | ||
}) | ||
} | ||
|
||
export const runtime = 'edge' |
Oops, something went wrong.