-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change Server Reference creation on client (#48824)
Mostly mirrors the changed made in facebook/react#26632 to our SWC transform. The implementation difference is that the AST transformer only adds a general purpose wrapper call `createServerReference(id)` from an aliased import, so we can easily change the underlying function in the bundler. This change only affects the client layer (when `self.config.is_server === false`). Needs to be landed after another React upgrade: #48697. cc @sebmarkbage.
- Loading branch information
Showing
8 changed files
with
148 additions
and
134 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
22 changes: 3 additions & 19 deletions
22
packages/next-swc/crates/core/tests/fixture/server-actions/client/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,20 +1,4 @@ | ||
// app/send.ts | ||
/* __next_internal_action_entry_do_not_use__ myAction,default */ export async function myAction(...args) { | ||
return __build_action__(myAction, args); | ||
} | ||
export default async function $$ACTION_0(...args) { | ||
return __build_action__($$ACTION_0, args); | ||
}; | ||
import ensureServerEntryExports from "private-next-rsc-action-proxy"; | ||
ensureServerEntryExports([ | ||
myAction, | ||
$$ACTION_0 | ||
]); | ||
myAction.$$typeof = Symbol.for("react.server.reference"); | ||
myAction.$$id = "e10665baac148856374b2789aceb970f66fec33e"; | ||
myAction.$$bound = []; | ||
myAction.$$with_bound = false; | ||
$$ACTION_0.$$typeof = Symbol.for("react.server.reference"); | ||
$$ACTION_0.$$id = "c18c215a6b7cdc64bf709f3a714ffdef1bf9651d"; | ||
$$ACTION_0.$$bound = []; | ||
$$ACTION_0.$$with_bound = false; | ||
/* __next_internal_action_entry_do_not_use__ myAction,default */ import createServerReference from "private-next-rsc-action-client-wrapper"; | ||
export const myAction = createServerReference("e10665baac148856374b2789aceb970f66fec33e"); | ||
export default createServerReference("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d"); |
13 changes: 2 additions & 11 deletions
13
packages/next-swc/crates/core/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,12 +1,3 @@ | ||
// app/send.ts | ||
/* __next_internal_action_entry_do_not_use__ foo */ export async function foo(...args) { | ||
return __build_action__(foo, args); | ||
} | ||
import ensureServerEntryExports from "private-next-rsc-action-proxy"; | ||
ensureServerEntryExports([ | ||
foo | ||
]); | ||
foo.$$typeof = Symbol.for("react.server.reference"); | ||
foo.$$id = "ab21efdafbe611287bc25c0462b1e0510d13e48b"; | ||
foo.$$bound = []; | ||
foo.$$with_bound = false; | ||
/* __next_internal_action_entry_do_not_use__ foo */ import createServerReference from "private-next-rsc-action-client-wrapper"; | ||
export const foo = createServerReference("ab21efdafbe611287bc25c0462b1e0510d13e48b"); |
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 +1,2 @@ | ||
declare module 'next/dist/compiled/react-server-dom-webpack/client' | ||
declare module 'next/dist/client/app-call-server' |
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
10 changes: 10 additions & 0 deletions
10
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// This file must be bundled in the app's client layer. | ||
|
||
import { createServerReference } from 'next/dist/compiled/react-server-dom-webpack/client' | ||
import { 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 default function (id: string) { | ||
return createServerReference(id, callServer) | ||
} |
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