mirror of https://github.com/alibaba/ice.git
fix: type error
This commit is contained in:
parent
bfc6dda579
commit
0de6c8ca8b
|
@ -31,7 +31,8 @@
|
|||
"@types/react-dom": "^19.0.0",
|
||||
"@tanstack/react-router": "^1.106.0",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0"
|
||||
"react-dom": "^19.0.0",
|
||||
"typescript": "^5.7.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ice/runtime-kit": "^0.1.0"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import React from 'react';
|
||||
import * as React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import { defineAppConfig, getAppConfig } from '@ice/runtime-kit';
|
||||
import type { RunClientAppOptions } from '@ice/runtime-kit';
|
||||
|
@ -12,6 +12,7 @@ const runClientApp = (options: RunClientAppOptions) => {
|
|||
|
||||
// Create router with optimized defaults
|
||||
const router = createRouter({
|
||||
// @ts-ignore
|
||||
routeTree: createRoutes,
|
||||
defaultPreload: 'intent',
|
||||
defaultStaleTime: DEFAULT_STALE_TIME,
|
||||
|
|
|
@ -31,8 +31,8 @@ interface Piper {
|
|||
}
|
||||
|
||||
interface Response {
|
||||
statusCode?: number;
|
||||
statusText?: string;
|
||||
statusCode: number;
|
||||
statusText: string;
|
||||
value?: string | Piper;
|
||||
headers?: Record<string, string>;
|
||||
}
|
||||
|
@ -56,10 +56,10 @@ export async function sendResponse(
|
|||
}
|
||||
}
|
||||
|
||||
export const getDocumentResponse = (
|
||||
export const getDocumentResponse = async (
|
||||
serverContext: ServerContext,
|
||||
renderOptions: any,
|
||||
): Response => {
|
||||
): Promise<Response> => {
|
||||
// TODO: get matches by serverContext.
|
||||
const {
|
||||
assetsManifest,
|
||||
|
@ -90,15 +90,18 @@ export const getDocumentResponse = (
|
|||
|
||||
const documentContext = { main: null };
|
||||
const htmlStr = ReactDOMServer.renderToString(
|
||||
// @ts-ignore fix the type error by union react types.
|
||||
<AppContextProvider value={appContext}>
|
||||
{/* @ts-ignore fix the type error by union react types */}
|
||||
<DocumentContextProvider value={documentContext}>
|
||||
{Document && <Document pagePath={routePath} />}
|
||||
{Document ? <Document pagePath={routePath} /> : null}
|
||||
</DocumentContextProvider>
|
||||
</AppContextProvider>,
|
||||
);
|
||||
|
||||
return {
|
||||
value: `<!DOCTYPE html>${htmlStr}`,
|
||||
statusText: '',
|
||||
headers: {
|
||||
'Content-Type': 'text/html; charset=utf-8',
|
||||
},
|
||||
|
@ -112,7 +115,9 @@ export const renderDocumentToResponse = async (
|
|||
): Promise<void> => {
|
||||
const { req, res } = serverContext;
|
||||
const response = await getDocumentResponse(serverContext, renderOptions);
|
||||
if (req && res) {
|
||||
await sendResponse(req, res, response);
|
||||
}
|
||||
};
|
||||
|
||||
export { getAppConfig };
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
"baseUrl": "./",
|
||||
"rootDir": "src",
|
||||
"outDir": "esm",
|
||||
"module": "ES2020"
|
||||
"module": "ES2020",
|
||||
"strictNullChecks": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
|
|
|
@ -2564,6 +2564,9 @@ importers:
|
|||
react-dom:
|
||||
specifier: ^19.0.0
|
||||
version: 19.0.0(react@19.0.0)
|
||||
typescript:
|
||||
specifier: ^5.7.3
|
||||
version: 5.7.3
|
||||
|
||||
packages/shared:
|
||||
devDependencies:
|
||||
|
@ -23694,6 +23697,12 @@ packages:
|
|||
engines: {node: '>=4.2.0'}
|
||||
hasBin: true
|
||||
|
||||
/typescript@5.7.3:
|
||||
resolution: {integrity: sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==}
|
||||
engines: {node: '>=14.17'}
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/ua-parser-js@1.0.40:
|
||||
resolution: {integrity: sha512-z6PJ8Lml+v3ichVojCiB8toQJBuwR42ySM4ezjXIqXK3M0HczmKQ3LF4rhU55PfD99KEEXQG6yb7iOMyvYuHew==}
|
||||
hasBin: true
|
||||
|
@ -24472,7 +24481,7 @@ packages:
|
|||
on-finished: 2.4.1
|
||||
range-parser: 1.2.1
|
||||
schema-utils: 4.3.0
|
||||
webpack: 5.88.2(@swc/core@1.3.80)(esbuild@0.25.0)
|
||||
webpack: 5.88.2(esbuild@0.25.0)
|
||||
dev: true
|
||||
|
||||
/webpack-dev-server@4.15.0(debug@4.4.0)(webpack@5.88.2):
|
||||
|
@ -24617,7 +24626,7 @@ packages:
|
|||
serve-index: 1.9.1
|
||||
sockjs: 0.3.24
|
||||
spdy: 4.0.2
|
||||
webpack: 5.88.2(@swc/core@1.3.80)(esbuild@0.25.0)
|
||||
webpack: 5.88.2(esbuild@0.25.0)
|
||||
webpack-dev-middleware: 7.4.2(webpack@5.88.2)
|
||||
ws: 8.18.0
|
||||
transitivePeerDependencies:
|
||||
|
|
Loading…
Reference in New Issue