Skip to content

Commit

Permalink
Merge branch 'canary' into 09-26-turbopack_build_fix_benchmark_runnin…
Browse files Browse the repository at this point in the history
…g_with_webpack
  • Loading branch information
timneutkens authored Sep 27, 2024
2 parents 25f0d7c + 2fc641e commit 3a62c2f
Show file tree
Hide file tree
Showing 63 changed files with 1,110 additions and 186 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ jobs:
strategy:
fail-fast: false
matrix:
exclude:
# Excluding React 18 tests unless on `canary` branch until budget is approved.
- react: ${{ github.event_name == 'pull_request' && '18.3.1' }}
group: [1/5, 2/5, 3/5, 4/5, 5/5]
# Empty value uses default
react: ['', '18.3.1']
Expand All @@ -219,6 +222,9 @@ jobs:
strategy:
fail-fast: false
matrix:
exclude:
# Excluding React 18 tests unless on `canary` branch until budget is approved.
- react: ${{ github.event_name == 'pull_request' && '18.3.1' }}
group: [1/5, 2/5, 3/5, 4/5, 5/5]
# Empty value uses default
react: ['']
Expand All @@ -237,6 +243,9 @@ jobs:
strategy:
fail-fast: false
matrix:
exclude:
# Excluding React 18 tests unless on `canary` branch until budget is approved.
- react: ${{ github.event_name == 'pull_request' && '18.3.1' }}
group: [1/5, 2/5, 3/5, 4/5, 5/5]
# Empty value uses default
# TODO: Run with React 18.
Expand Down Expand Up @@ -372,6 +381,9 @@ jobs:
strategy:
fail-fast: false
matrix:
exclude:
# Excluding React 18 tests unless on `canary` branch until budget is approved.
- react: ${{ github.event_name == 'pull_request' && '18.3.1' }}
group: [1/4, 2/4, 3/4, 4/4]
# Empty value uses default
react: ['', '18.3.1']
Expand All @@ -389,6 +401,9 @@ jobs:
strategy:
fail-fast: false
matrix:
exclude:
# Excluding React 18 tests unless on `canary` branch until budget is approved.
- react: ${{ github.event_name == 'pull_request' && '18.3.1' }}
group: [1/5, 2/5, 3/5, 4/5, 5/5]
# Empty value uses default
react: ['', '18.3.1']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ impl ReactServerComponentValidator {
}
}

/// ```
/// ```js
/// import dynamic from 'next/dynamic'
///
/// dynamic(() => import(...)) // ✅
Expand Down
58 changes: 43 additions & 15 deletions crates/next-custom-transforms/src/transforms/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,18 +1345,38 @@ impl<C: Comments> VisitMut for ServerActions<C> {
// If it's compiled in the client layer, each export field needs to be
// wrapped by a reference creation call.
let create_ref_ident = private_ident!("createServerReference");
let call_server_ident = private_ident!("callServer");
let find_source_map_url_ident = private_ident!("findSourceMapURL");

if !self.config.is_react_server_layer {
// import { createServerReference } from
// 'private-next-rsc-action-client-wrapper'
// import {
// createServerReference,
// callServer,
// findSourceMapURL
// } from 'private-next-rsc-action-client-wrapper'
// createServerReference("action_id")
new.push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl {
span: DUMMY_SP,
specifiers: vec![ImportSpecifier::Named(ImportNamedSpecifier {
span: DUMMY_SP,
local: create_ref_ident.clone(),
imported: None,
is_type_only: false,
})],
specifiers: vec![
ImportSpecifier::Named(ImportNamedSpecifier {
span: DUMMY_SP,
local: create_ref_ident.clone(),
imported: None,
is_type_only: false,
}),
ImportSpecifier::Named(ImportNamedSpecifier {
span: DUMMY_SP,
local: call_server_ident.clone(),
imported: None,
is_type_only: false,
}),
ImportSpecifier::Named(ImportNamedSpecifier {
span: DUMMY_SP,
local: find_source_map_url_ident.clone(),
imported: None,
is_type_only: false,
}),
],
src: Box::new(Str {
span: DUMMY_SP,
value: "private-next-rsc-action-client-wrapper".into(),
Expand All @@ -1366,6 +1386,7 @@ impl<C: Comments> VisitMut for ServerActions<C> {
with: None,
phase: Default::default(),
})));
new.rotate_right(1);
}

for (id, export_name) in self.exported_idents.iter() {
Expand All @@ -1386,7 +1407,13 @@ impl<C: Comments> VisitMut for ServerActions<C> {
callee: Callee::Expr(Box::new(Expr::Ident(
create_ref_ident.clone(),
))),
args: vec![action_id.as_arg()],
args: vec![
action_id.as_arg(),
call_server_ident.clone().as_arg(),
Expr::undefined(DUMMY_SP).as_arg(),
find_source_map_url_ident.clone().as_arg(),
"default".as_arg(),
],
..Default::default()
})),
},
Expand All @@ -1410,7 +1437,13 @@ impl<C: Comments> VisitMut for ServerActions<C> {
callee: Callee::Expr(Box::new(Expr::Ident(
create_ref_ident.clone(),
))),
args: vec![action_id.as_arg()],
args: vec![
action_id.as_arg(),
call_server_ident.clone().as_arg(),
Expr::undefined(DUMMY_SP).as_arg(),
find_source_map_url_ident.clone().as_arg(),
export_name.clone().as_arg(),
],
..Default::default()
}))),
definite: false,
Expand Down Expand Up @@ -1520,11 +1553,6 @@ impl<C: Comments> VisitMut for ServerActions<C> {
text: generate_server_actions_comment(actions).into(),
},
);

if !self.config.is_react_server_layer {
// Make it the first item
new.rotate_right(1);
}
}

// import { cache as $cache } from "private-next-rsc-cache-wrapper";
Expand Down
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() {}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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");

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1897,12 +1897,14 @@ export default async function build(
distDir,
configFileName,
runtimeEnvConfig,
dynamicIO: Boolean(config.experimental.dynamicIO),
httpAgentOptions: config.httpAgentOptions,
locales: config.i18n?.locales,
defaultLocale: config.i18n?.defaultLocale,
nextConfigOutput: config.output,
pprConfig: config.experimental.ppr,
isAppPPRFallbacksEnabled: config.experimental.pprFallbacks,
buildId,
})
)

Expand Down Expand Up @@ -2112,6 +2114,7 @@ export default async function build(
pageRuntime,
edgeInfo,
pageType,
dynamicIO: Boolean(config.experimental.dynamicIO),
cacheHandler: config.cacheHandler,
isrFlushToDisk: ciEnvironment.hasNextSupport
? false
Expand All @@ -2121,6 +2124,7 @@ export default async function build(
pprConfig: config.experimental.ppr,
isAppPPRFallbacksEnabled:
config.experimental.pprFallbacks,
buildId,
})
}
)
Expand Down
14 changes: 13 additions & 1 deletion packages/next/src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,7 @@ export async function buildAppStaticPaths({
dir,
page,
distDir,
dynamicIO,
configFileName,
generateParams,
isrFlushToDisk,
Expand All @@ -1359,9 +1360,11 @@ export async function buildAppStaticPaths({
ComponentMod,
isRoutePPREnabled,
isAppPPRFallbacksEnabled,
buildId,
}: {
dir: string
page: string
dynamicIO: boolean
configFileName: string
generateParams: GenerateParamsResults
distDir: string
Expand All @@ -1374,6 +1377,7 @@ export async function buildAppStaticPaths({
ComponentMod: AppPageModule
isRoutePPREnabled: boolean | undefined
isAppPPRFallbacksEnabled: boolean | undefined
buildId: string
}): Promise<PartialStaticPathsResult> {
ComponentMod.patchFetch()

Expand All @@ -1390,6 +1394,7 @@ export async function buildAppStaticPaths({
const incrementalCache = new IncrementalCache({
fs: nodeFs,
dev: true,
dynamicIO,
flushToDisk: isrFlushToDisk,
serverDistDir: path.join(distDir, 'server'),
fetchCacheKeyPrefix,
Expand Down Expand Up @@ -1419,8 +1424,9 @@ export async function buildAppStaticPaths({
isRevalidate: false,
experimental: {
after: false,
dynamicIO: false,
dynamicIO,
},
buildId,
},
},
async (): Promise<PartialStaticPathsResult> => {
Expand Down Expand Up @@ -1581,17 +1587,20 @@ export async function isPageStatic({
pageRuntime,
edgeInfo,
pageType,
dynamicIO,
originalAppPath,
isrFlushToDisk,
maxMemoryCacheSize,
nextConfigOutput,
cacheHandler,
pprConfig,
isAppPPRFallbacksEnabled,
buildId,
}: {
dir: string
page: string
distDir: string
dynamicIO: boolean
configFileName: string
runtimeEnvConfig: any
httpAgentOptions: NextConfigComplete['httpAgentOptions']
Expand All @@ -1608,6 +1617,7 @@ export async function isPageStatic({
nextConfigOutput: 'standalone' | 'export' | undefined
pprConfig: ExperimentalPPRConfig | undefined
isAppPPRFallbacksEnabled: boolean | undefined
buildId: string
}): Promise<PageIsStaticResult> {
const isPageStaticSpan = trace('is-page-static-utils', parentId)
return isPageStaticSpan
Expand Down Expand Up @@ -1722,6 +1732,7 @@ export async function isPageStatic({
await buildAppStaticPaths({
dir,
page,
dynamicIO,
configFileName,
generateParams,
distDir,
Expand All @@ -1733,6 +1744,7 @@ export async function isPageStatic({
nextConfigOutput,
isRoutePPREnabled,
isAppPPRFallbacksEnabled,
buildId,
}))
}
} else {
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const flightServerReferenceProxyLoader: webpack.LoaderDefinitionFunction<{
// Because of that, Webpack is able to concatenate the modules and inline the
// reference IDs recursively directly into the module that uses them.
return `\
import { createServerReference } from 'private-next-rsc-action-client-wrapper'
import { createServerReference, callServer, findSourceMapURL } from 'private-next-rsc-action-client-wrapper'
export ${
name === 'default' ? 'default' : `const ${name} =`
} /*#__PURE__*/createServerReference(${JSON.stringify(id)})`
} /*#__PURE__*/createServerReference(${JSON.stringify(id)}, callServer, undefined, findSourceMapURL, ${JSON.stringify(name)})`
}

export default flightServerReferenceProxyLoader
Loading

0 comments on commit 3a62c2f

Please sign in to comment.