From 9f3bcd13c5e8af9fdcdbc34e8a0595c783883d10 Mon Sep 17 00:00:00 2001 From: Kuitos Date: Tue, 24 Oct 2023 17:25:46 +0800 Subject: [PATCH 1/2] fix: transformer should be generated in every load --- packages/loader/src/index.ts | 13 ++++++++----- packages/qiankun/src/core/loadApp.ts | 4 ++-- packages/qiankun/src/types.ts | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/loader/src/index.ts b/packages/loader/src/index.ts index ce4f80d61..2264e826d 100644 --- a/packages/loader/src/index.ts +++ b/packages/loader/src/index.ts @@ -18,7 +18,7 @@ type Entry = HTMLEntry; // }; // export type LoaderOpts = { - transformer?: TransformStream; + streamTransformer?: () => TransformStream; nodeTransformer?: typeof transpileAssets; } & BaseTranspilerOpts & { sandbox?: Sandbox }; @@ -31,14 +31,14 @@ export async function loadEntry(entry: Entry, container: HTMLElement, opts: L const { fetch, nodeTransformer = transpileAssets, - transformer, + streamTransformer, sandbox, moduleResolver = (url: string) => { return defaultModuleResolver(url, container, document.head); }, } = opts; - const res = isUrlHasOwnProtocol(entry) ? await fetch(entry) : new Response(entry); + const res = isUrlHasOwnProtocol(entry) ? await fetch(entry) : new Response(entry, { status: 200, statusText: 'OK' }); if (res.body) { let noExternalScript = true; const entryScriptLoadedDeferred = new Deferred(); @@ -46,8 +46,8 @@ export async function loadEntry(entry: Entry, container: HTMLElement, opts: L let readableStream = res.body.pipeThrough(new TextDecoderStream()); - if (transformer) { - readableStream = readableStream.pipeThrough(transformer); + if (streamTransformer) { + readableStream = readableStream.pipeThrough(streamTransformer()); } void readableStream @@ -135,6 +135,9 @@ export async function loadEntry(entry: Entry, container: HTMLElement, opts: L if (noExternalScript) { entryScriptLoadedDeferred.resolve(); } + }) + .catch((e) => { + entryScriptLoadedDeferred.reject(e); }); return entryScriptLoadedDeferred.promise; diff --git a/packages/qiankun/src/core/loadApp.ts b/packages/qiankun/src/core/loadApp.ts index 77efe22c7..46341978b 100644 --- a/packages/qiankun/src/core/loadApp.ts +++ b/packages/qiankun/src/core/loadApp.ts @@ -28,7 +28,7 @@ export default async function loadApp( lifeCycles?: LifeCycles, ) { const { name: appName, entry, container } = app; - const { fetch = window.fetch, sandbox, globalContext = window, transformer } = configuration || {}; + const { fetch = window.fetch, sandbox, globalContext = window, streamTransformer } = configuration || {}; const markName = `[qiankun] App ${appName} Loading`; if (process.env.NODE_ENV === 'development') { @@ -56,7 +56,7 @@ export default async function loadApp( unmountSandbox = () => sandboxContainer.unmount(); } - const containerOpts: LoaderOpts = { fetch, sandbox: sandboxInstance, transformer }; + const containerOpts: LoaderOpts = { fetch, sandbox: sandboxInstance, streamTransformer }; const lifecyclesPromise = loadEntry(entry, microAppContainer, containerOpts); diff --git a/packages/qiankun/src/types.ts b/packages/qiankun/src/types.ts index 3760d5b0b..ec741a96e 100644 --- a/packages/qiankun/src/types.ts +++ b/packages/qiankun/src/types.ts @@ -41,7 +41,7 @@ export type RegistrableApp = LoadableApp & { activeRule: RegisterApplicationConfig['activeWhen']; }; -export type AppConfiguration = Pick & { +export type AppConfiguration = Pick & { sandbox?: boolean; globalContext?: WindowProxy; }; From 16996101a4db6283ed04737c907188e2957be193 Mon Sep 17 00:00:00 2001 From: Kuitos Date: Tue, 24 Oct 2023 17:26:52 +0800 Subject: [PATCH 2/2] Create tough-beers-grow.md --- .changeset/tough-beers-grow.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/tough-beers-grow.md diff --git a/.changeset/tough-beers-grow.md b/.changeset/tough-beers-grow.md new file mode 100644 index 000000000..ebe658849 --- /dev/null +++ b/.changeset/tough-beers-grow.md @@ -0,0 +1,6 @@ +--- +"@qiankunjs/loader": patch +"qiankun": patch +--- + +fix: transformer should be generated in every load