Skip to content

Commit

Permalink
fix: multi-instance bug and unhandled error for live demo feature (#2078
Browse files Browse the repository at this point in the history
)

* fix: external resolve and skip server render handle for liveDemo

* fix: 依赖不再使用绝对路径

* fix: delete external
  • Loading branch information
Jinbao1001 committed Apr 24, 2024
1 parent 8cdc32b commit 0df859e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/assetParsers/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async function parseBlockAsset(opts: {
value: pkg.version,
};

result.resolveMap[args.path] = resolved;
result.resolveMap[args.path] = args.path;
}

// make all deps external
Expand Down Expand Up @@ -179,7 +179,10 @@ async function parseBlockAsset(opts: {

// save file absolute path for load file via raw-loader
// to avoid bundle same file to save bundle size
if (!isEntryPoint || !opts.entryPointCode) {
if (
opts.techStack.runtimeOpts &&
(!isEntryPoint || !opts.entryPointCode)
) {
result.resolveMap[filename] = args.path;
}

Expand Down
13 changes: 12 additions & 1 deletion src/client/theme-api/useLiveDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,18 @@ export const useLiveDemo = (
oError.apply(console, args);

// check component is able to render, to avoid show react overlay error
(await renderToStaticMarkupDeferred)(newDemoNode);
try {
(await renderToStaticMarkupDeferred)(newDemoNode);
} catch (err: any) {
const shouldSkipError =
err.message.includes(
'Unable to find node on an unmounted component',
) ||
err.message.includes(
'Portals are not currently supported by the server renderer',
);
if (!shouldSkipError) throw err;
}
console.error = oError;

// set new demo node with passing source
Expand Down
5 changes: 4 additions & 1 deletion src/loaders/markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { isTabRouteFile } from '@/features/tabs';
import type { IThemeLoadResult } from '@/features/theme/loader';
import { generateMetaChunkName, getCache, getContentHash } from '@/utils';
import fs from 'fs';
import path from 'path';
import { Mustache, lodash, winPath } from 'umi/plugin-utils';
import transform, {
type IMdTransformerOptions,
Expand Down Expand Up @@ -58,7 +59,9 @@ export type IMdLoaderOptions =
function getDemoSourceFiles(demos: IMdTransformerResult['meta']['demos'] = []) {
return demos.reduce<string[]>((ret, demo) => {
if ('resolveMap' in demo) {
ret.push(...Object.values(demo.resolveMap));
ret.push(
...Object.values(demo.resolveMap).filter((p) => path.isAbsolute(p)),
);
}

return ret;
Expand Down
2 changes: 1 addition & 1 deletion suites/theme-mobile/src/builtins/Previewer/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
&:first-child + .dumi-default-previewer-sources {
border-top: 1px dashed @c-border-light;
margin-top: 42px;

overflow: auto;
@{dark-selector} & {
border-top-color: @c-border-less-dark;
}
Expand Down

0 comments on commit 0df859e

Please sign in to comment.