Skip to content

Commit

Permalink
chore: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zllkjc committed Mar 3, 2025
1 parent a9e46bf commit 1b4bbd0
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/runtime/plugin-runtime/src/core/compatible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const bootstrap: BootStrap = async (
loaderManager: createLoaderManager(initialLoadersState, {
skipStatic: true,
}),
ssrContext: ssrData?.context,
ssrContext: ssrData?.context || {},
});

context.initialData = ssrData?.data?.initialData;
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions tests/integration/ssr/fixtures/init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dependencies": {
"@modern-js/app-tools": "workspace:*",
"@modern-js/runtime": "workspace:*",
"@modern-js/tsconfig": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.3.1"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { useRuntimeContext } from '@modern-js/runtime';
import { type RuntimeContext, useRuntimeContext } from '@modern-js/runtime';

const App = () => {
const context = useRuntimeContext();
const { initialData } = useRuntimeContext();
return (
<div className="text-center" id="data">
Hello, Modern.js. env name: {context.initialData?.name}
Hello, Modern.js. env name: {(initialData?.name || '') as string}
</div>
);
};

App.init = context => {
const { request } = context.ssrContext;
App.init = (context: RuntimeContext) => {
const { request } = context.context!;

if (context.isBrowser && !context?.initialData?.name) {
return {
Expand Down
14 changes: 14 additions & 0 deletions tests/integration/ssr/fixtures/init/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "@modern-js/tsconfig/base",
"compilerOptions": {
"declaration": false,
"jsx": "preserve",
"baseUrl": "./",
"paths": {
"@/*": ["./src/*"],
"@shared/*": ["./shared/*"],
"@api/*": ["./api/*"]
}
},
"include": ["src", "shared", "config", "modern.config.ts", "api", "server"]
}

0 comments on commit 1b4bbd0

Please sign in to comment.