Skip to content

Commit 861393b

Browse files
authored
fix: string ssr not generate initialData and i18nData (#7858)
1 parent 930a9b6 commit 861393b

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

packages/runtime/plugin-runtime/src/core/server/string/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export const renderString: RenderString = async (
5757
config,
5858
}),
5959
new SSRDataCollector({
60+
runtimeContext,
6061
request,
6162
ssrConfig,
6263
ssrContext: runtimeContext.ssrContext!,

packages/runtime/plugin-runtime/src/core/server/string/ssrData.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import { serializeJson } from '@modern-js/runtime-utils/node';
33
import type { StaticHandlerContext } from '@modern-js/runtime-utils/router';
44
import type { HeadersData } from '@modern-js/runtime-utils/universal/request';
55
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from '../../constants';
6+
import type { RuntimeContext } from '../../context';
67
import type { SSRContainer, SSRServerContext } from '../../types';
78
import type { SSRConfig } from '../shared';
89
import { attributesToString, serializeErrors } from '../utils';
910
import type { ChunkSet, Collector } from './types';
1011

1112
export interface SSRDataCreatorOptions {
13+
runtimeContext: RuntimeContext;
1214
request: Request;
1315
chunkSet: ChunkSet;
1416
ssrContext: SSRServerContext;
@@ -42,7 +44,7 @@ export class SSRDataCollector implements Collector {
4244
}
4345

4446
#getSSRData(): SSRContainer {
45-
const { chunkSet, ssrConfig, ssrContext } = this.#options;
47+
const { chunkSet, ssrConfig, ssrContext, runtimeContext } = this.#options;
4648

4749
const { reporter, request } = ssrContext;
4850

@@ -60,6 +62,10 @@ export class SSRDataCollector implements Collector {
6062
: undefined;
6163

6264
return {
65+
data: {
66+
initialData: runtimeContext.initialData,
67+
i18nData: runtimeContext.__i18nData__,
68+
},
6369
context: {
6470
request: {
6571
params: request.params,

packages/runtime/plugin-runtime/src/core/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ declare global {
1111

1212
export interface SSRData {
1313
initialData?: Record<string, unknown>;
14+
i18nData?: Record<string, unknown>;
1415
[props: string]: any;
1516
}
1617

0 commit comments

Comments
 (0)