-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transform client reference in middleware layer (#66294)
### What Use `next-flight-loader` to transform the client components into client reference in middleware and instrumentation. Add related required webpack aliases, such as alias for `react-server-dom-webpack` ### Why issue reported in #65424 (comment)
- Loading branch information
Showing
15 changed files
with
97 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Link from 'next/link' | ||
|
||
export const textValue = 'text-value' | ||
export const TestLink = Link |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Layout({ children }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
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,3 @@ | ||
export default function Page() { | ||
return 'page' | ||
} |
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 React from 'react' | ||
import { textValue } from './lib/shared-module' | ||
|
||
export async function register() { | ||
// TODO: support react-server condition for instrumentation hook in turbopack | ||
if (!process.env.TURBOPACK && Object(React).useState) { | ||
throw new Error('instrumentation is not working correctly in server layer') | ||
} | ||
console.log('instrumentation:register') | ||
console.log('instrumentation:text:' + textValue) | ||
} |
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,4 @@ | ||
import Link from 'next/link' | ||
|
||
export const textValue = 'text-value' | ||
export const TestLink = Link |
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,13 @@ | ||
import { NextResponse } from 'next/server' | ||
import { textValue, TestLink } from './lib/shared-module' | ||
|
||
export function middleware(request) { | ||
if (request.nextUrl.pathname === '/middleware') { | ||
return Response.json({ | ||
clientReference: TestLink.$$typeof.toString(), | ||
textValue, | ||
}) | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
experimental: { | ||
instrumentationHook: true, | ||
}, | ||
} |
26 changes: 26 additions & 0 deletions
26
test/e2e/rsc-layers-transform/rsc-layers-transform.test.ts
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,26 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
|
||
// TODO: support react-server condition for instrumentation hook in turbopack | ||
;(process.env.TURBOPACK ? describe.skip : describe)( | ||
'rsc layers transform', | ||
() => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should render installed react-server condition for middleware', async () => { | ||
const json = await next.fetch('/middleware').then((res) => res.json()) | ||
|
||
expect(json).toEqual({ | ||
textValue: 'text-value', | ||
clientReference: 'Symbol(react.client.reference)', | ||
}) | ||
}) | ||
|
||
it('should call instrumentation hook without errors', async () => { | ||
const output = next.cliOutput | ||
expect(output).toContain('instrumentation:register') | ||
expect(output).toContain('instrumentation:text:text-value') | ||
}) | ||
} | ||
) |