Skip to content

Commit 7faa51d

Browse files
committed
use a different api
1 parent d09dd56 commit 7faa51d

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

packages/next-swc/crates/next-api/src/app.rs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ impl AppProject {
283283
))),
284284
),
285285
("next-ssr".to_string(), Vc::upcast(self.ssr_transition())),
286+
(
287+
"next-shared".to_string(),
288+
Vc::upcast(self.shared_transition()),
289+
),
286290
]
287291
.into_iter()
288292
.collect();
@@ -315,6 +319,10 @@ impl AppProject {
315319
"next-ssr".to_string(),
316320
Vc::upcast(self.edge_ssr_transition()),
317321
),
322+
(
323+
"next-shared".to_string(),
324+
Vc::upcast(self.edge_shared_transition()),
325+
),
318326
]
319327
.into_iter()
320328
.collect();
@@ -344,6 +352,10 @@ impl AppProject {
344352
))),
345353
),
346354
("next-ssr".to_string(), Vc::upcast(self.ssr_transition())),
355+
(
356+
"next-shared".to_string(),
357+
Vc::upcast(self.shared_transition()),
358+
),
347359
]
348360
.into_iter()
349361
.collect();
@@ -359,8 +371,30 @@ impl AppProject {
359371

360372
#[turbo_tasks::function]
361373
fn edge_route_module_context(self: Vc<Self>) -> Vc<ModuleAssetContext> {
374+
let transitions = [
375+
(
376+
ECMASCRIPT_CLIENT_TRANSITION_NAME.to_string(),
377+
Vc::upcast(NextEcmascriptClientReferenceTransition::new(
378+
Vc::upcast(self.client_transition()),
379+
self.edge_ssr_transition(),
380+
)),
381+
),
382+
(
383+
"next-dynamic".to_string(),
384+
Vc::upcast(NextDynamicTransition::new(Vc::upcast(
385+
self.client_transition(),
386+
))),
387+
),
388+
("next-ssr".to_string(), Vc::upcast(self.ssr_transition())),
389+
(
390+
"next-shared".to_string(),
391+
Vc::upcast(self.edge_shared_transition()),
392+
),
393+
]
394+
.into_iter()
395+
.collect();
362396
ModuleAssetContext::new(
363-
Default::default(),
397+
Vc::cell(transitions),
364398
self.project().edge_compile_time_info(),
365399
self.edge_route_module_options_context(),
366400
self.edge_route_resolve_options_context(),
@@ -435,6 +469,16 @@ impl AppProject {
435469
)
436470
}
437471

472+
#[turbo_tasks::function]
473+
fn shared_transition(self: Vc<Self>) -> Vc<ContextTransition> {
474+
ContextTransition::new(
475+
self.project().server_compile_time_info(),
476+
self.ssr_module_options_context(),
477+
self.ssr_resolve_options_context(),
478+
Vc::cell("app-shared".to_string()),
479+
)
480+
}
481+
438482
#[turbo_tasks::function]
439483
fn edge_ssr_transition(self: Vc<Self>) -> Vc<ContextTransition> {
440484
ContextTransition::new(
@@ -445,6 +489,16 @@ impl AppProject {
445489
)
446490
}
447491

492+
#[turbo_tasks::function]
493+
fn edge_shared_transition(self: Vc<Self>) -> Vc<ContextTransition> {
494+
ContextTransition::new(
495+
self.project().edge_compile_time_info(),
496+
self.edge_ssr_module_options_context(),
497+
self.edge_ssr_resolve_options_context(),
498+
Vc::cell("app-edge-shared".to_string()),
499+
)
500+
}
501+
448502
#[turbo_tasks::function]
449503
async fn runtime_entries(self: Vc<Self>) -> Result<Vc<RuntimeEntries>> {
450504
Ok(get_server_runtime_entries(

packages/next/src/client/components/request-async-storage.external.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ResponseCookies } from '../../server/web/spec-extension/cookies'
44
import type { ReadonlyHeaders } from '../../server/web/spec-extension/adapters/headers'
55
import type { ReadonlyRequestCookies } from '../../server/web/spec-extension/adapters/request-cookies'
66

7+
;('TURBOPACK { transition: next-shared }')
78
import { createAsyncLocalStorage } from './async-local-storage'
89
import type { DeepReadonly } from '../../shared/lib/deep-readonly'
910

packages/next/src/shared/lib/lazy-dynamic/preload-css.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
'use client'
22

3-
import { getExpectedRequestStore } from '../../../client/components/request-async-storage.external'
3+
import { requestAsyncStorage } from '../../../client/components/request-async-storage.external'
44

55
export function PreloadCss({ moduleIds }: { moduleIds: string[] | undefined }) {
66
// Early return in client compilation and only load requestStore on server side
77
if (typeof window !== 'undefined') {
88
return null
99
}
1010

11-
const requestStore = getExpectedRequestStore('next/dynamic css')
12-
11+
const requestStore = requestAsyncStorage.getStore()
1312
const allFiles = []
1413

1514
// Search the current dynamic call unique key id in react loadable manifest,
1615
// and find the corresponding CSS files to preload
17-
if (requestStore.reactLoadableManifest && moduleIds) {
16+
if (requestStore?.reactLoadableManifest && moduleIds) {
1817
const manifest = requestStore.reactLoadableManifest
1918
for (const key of moduleIds) {
2019
if (!manifest[key]) continue

0 commit comments

Comments
 (0)