forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unwrap
createServerReference
, and pass additional parameters (verce…
…l#69190) For facebook/react#30741 This PR adds several additional parameters to the `createServerReference` calls generated by the Server Reference SWC transform, to later enable React to map server actions that are imported into client components back to their server locations (dev mode only). Currently the inner `findSourceMapURL` function is not yet implemented. In a follow-up we will unwrap `registerServerReference` as well, which is needed for server actions in the react server layer. --------- Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>
- Loading branch information
Showing
10 changed files
with
75 additions
and
49 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
4 changes: 2 additions & 2 deletions
4
crates/next-custom-transforms/tests/errors/server-actions/client-graph/1/output.js
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,5 +1,5 @@ | ||
/* __next_internal_client_entry_do_not_use__ default auto */ /* __next_internal_action_entry_do_not_use__ {"6a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0"} */ export async function $$RSC_SERVER_ACTION_0() {} | ||
export default function App() { | ||
/* __next_internal_client_entry_do_not_use__ default auto */ /* __next_internal_action_entry_do_not_use__ {"6a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0"} */ export default function App() { | ||
var fn = registerServerReference("6a88810ecce4a4e8b59d53b8327d7e98bbf251d7", $$RSC_SERVER_ACTION_0); | ||
return <div>App</div>; | ||
} | ||
export async function $$RSC_SERVER_ACTION_0() {} |
6 changes: 3 additions & 3 deletions
6
crates/next-custom-transforms/tests/fixture/server-actions/client/1/output.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
crates/next-custom-transforms/tests/fixture/server-actions/client/2/output.js
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,3 +1,3 @@ | ||
// app/send.ts | ||
/* __next_internal_action_entry_do_not_use__ {"ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo"} */ export var foo = /*#__PURE__*/ createServerReference("ab21efdafbe611287bc25c0462b1e0510d13e48b"); | ||
import { createServerReference } from "private-next-rsc-action-client-wrapper"; | ||
/* __next_internal_action_entry_do_not_use__ {"ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo"} */ import { createServerReference, callServer, findSourceMapURL } from "private-next-rsc-action-client-wrapper"; | ||
export var foo = /*#__PURE__*/ createServerReference("ab21efdafbe611287bc25c0462b1e0510d13e48b", callServer, void 0, findSourceMapURL, "foo"); |
10 changes: 5 additions & 5 deletions
10
crates/next-custom-transforms/tests/fixture/server-actions/client/3/output.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
crates/next-custom-transforms/tests/fixture/server-actions/client/4/output.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
crates/next-custom-transforms/tests/fixture/server-actions/client/5/output.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
28 changes: 13 additions & 15 deletions
28
packages/next/src/build/webpack/loaders/next-flight-loader/action-client-wrapper.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 |
---|---|---|
@@ -1,22 +1,20 @@ | ||
// This file must be bundled in the app's client layer, it shouldn't be directly | ||
// imported by the server. | ||
|
||
import { callServer } from 'next/dist/client/app-call-server' | ||
export { callServer } from 'next/dist/client/app-call-server' | ||
|
||
// A noop wrapper to let the Flight client create the server reference. | ||
// See also: https://github.com/facebook/react/pull/26632 | ||
export function createServerReference(id: string) { | ||
// Since we're using the Edge build of Flight client for SSR [1], here we need to | ||
// also use the same Edge build to create the reference. For the client bundle, | ||
// we use the default and let Webpack to resolve it to the correct version. | ||
// 1: https://github.com/vercel/next.js/blob/16eb80b0b0be13f04a6407943664b5efd8f3d7d0/packages/next/src/server/app-render/use-flight-response.tsx#L24-L26 | ||
const { createServerReference: createServerReferenceImpl } = ( | ||
!!process.env.NEXT_RUNTIME | ||
? // eslint-disable-next-line import/no-extraneous-dependencies | ||
require('react-server-dom-webpack/client.edge') | ||
: // eslint-disable-next-line import/no-extraneous-dependencies | ||
require('react-server-dom-webpack/client') | ||
) as typeof import('react-server-dom-webpack/client') | ||
// Since we're using the Edge build of Flight client for SSR [1], here we need to | ||
// also use the same Edge build to create the reference. For the client bundle, | ||
// we use the default and let Webpack to resolve it to the correct version. | ||
// 1: https://github.com/vercel/next.js/blob/16eb80b0b0be13f04a6407943664b5efd8f3d7d0/packages/next/src/server/app-render/use-flight-response.tsx#L24-L26 | ||
export const createServerReference = ( | ||
(!!process.env.NEXT_RUNTIME | ||
? // eslint-disable-next-line import/no-extraneous-dependencies | ||
require('react-server-dom-webpack/client.edge') | ||
: // eslint-disable-next-line import/no-extraneous-dependencies | ||
require('react-server-dom-webpack/client')) as typeof import('react-server-dom-webpack/client') | ||
).createServerReference | ||
|
||
return createServerReferenceImpl(id, callServer) | ||
} | ||
export const findSourceMapURL = undefined |
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