Files
RustUI/.dumi/tmp-production/testBrowser.tsx
T

90 lines
2.8 KiB
TypeScript
Raw Normal View History

2026-05-31 09:36:07 +08:00
// @ts-nocheck
// This file is generated by Umi automatically
// DO NOT CHANGE IT MANUALLY!
import React, { useEffect, useState } from 'react';
import { ApplyPluginsType } from 'umi';
2026-06-01 17:07:08 +08:00
import { renderClient, RenderClientOpts } from '/Users/donghym/Desktop/day/UI/Pika/node_modules/.pnpm/@umijs+renderer-react@4.6.56_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@umijs/renderer-react';
2026-05-31 09:36:07 +08:00
import { createHistory } from './core/history';
import { createPluginManager } from './core/plugin';
import { getRoutes } from './core/route';
import type { Location } from 'history';
import { getPluginManager as getDumiPluginManager } from './core/plugin';
2026-06-01 17:07:08 +08:00
import { setPluginManager as setDumiPluginManager } from '/Users/donghym/Desktop/day/UI/Pika/node_modules/.pnpm/dumi@2.4.28_@babel+core@7.29.7_@types+node@25.9.1_@types+react@19.2.15_eslint@10.4.0_ji_4b5099ce8b49e6def696b2efaf0f9b24/node_modules/dumi/dist/client/theme-api/utils.js';
2026-05-31 09:36:07 +08:00
const publicPath = '/';
const runtimePublicPath = false;
type TestBrowserProps = {
location?: Partial<Location>;
historyRef?: React.MutableRefObject<Location>;
};
export function TestBrowser(props: TestBrowserProps) {
const pluginManager = createPluginManager();
const [context, setContext] = useState<RenderClientOpts | undefined>(
undefined
);
useEffect(() => {
const genContext = async () => {
const { routes, routeComponents } = await getRoutes(pluginManager);
// allow user to extend routes
await pluginManager.applyPlugins({
key: 'patchRoutes',
type: ApplyPluginsType.event,
args: {
routes,
routeComponents,
},
});
const contextOpts = pluginManager.applyPlugins({
key: 'modifyContextOpts',
type: ApplyPluginsType.modify,
initialValue: {},
});
const basename = contextOpts.basename || '/';
const history = createHistory({
type: 'memory',
basename,
});
const context = {
routes,
routeComponents,
pluginManager,
rootElement: contextOpts.rootElement || document.getElementById('root'),
publicPath,
runtimePublicPath,
history,
basename,
components: true,
};
const modifiedContext = pluginManager.applyPlugins({
key: 'modifyClientRenderOpts',
type: ApplyPluginsType.modify,
initialValue: context,
});
return modifiedContext;
};
genContext().then((context) => {
setContext(context);
if (props.location) {
context?.history?.push(props.location);
}
if (props.historyRef) {
props.historyRef.current = context?.history;
}
});
}, []);
if (context === undefined) {
return <div id="loading" />;
}
const Children = renderClient(context);
return (
<React.Fragment>
<Children />
</React.Fragment>
);
}