Skip to content

Commit

Permalink
fix: dynamic append js-module script error (#18)
Browse files Browse the repository at this point in the history
* fix: dynamic append js-module script error

* feat: add crossorigin & crossoriginType for js-module script
  • Loading branch information
Molunerfinn authored Jul 28, 2022
1 parent 8e7c710 commit 1181351
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/wujie-core/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { insertScriptToIframe } from "./iframe";
import Wujie from "./sandbox";
import { getHostCssRules } from "./shadow";
import { WUJIE_DATA_ID, WUJIE_DATA_FLAG, WUJIE_TIPS_REPEAT_RENDER } from "./constant";
import { ScriptObject } from "./template";

function patchCustomEvent(
e: CustomEvent,
Expand Down Expand Up @@ -180,7 +181,7 @@ function rewriteAppendOrInsertChild(opts: {
return rawDOMAppendOrInsertBefore.call(this, element, refChild);
}
case "SCRIPT": {
const { src, text } = element as HTMLScriptElement;
const { src, text, type, crossOrigin } = element as HTMLScriptElement;
// 排除js
if (
src &&
Expand All @@ -197,7 +198,13 @@ function rewriteAppendOrInsertChild(opts: {
manualInvokeElementEvent(element, "load");
element = null;
};
getExternalScripts([{ src }], fetch, lifecycles.loadError).forEach((scriptResult) =>
const scriptOptions = {
src,
module: type === "module",
crossorigin: crossOrigin !== null,
crossoriginType: crossOrigin || "",
} as ScriptObject;
getExternalScripts([scriptOptions], fetch, lifecycles.loadError).forEach((scriptResult) =>
scriptResult.contentPromise.then(
(content) => {
if (sandbox.execQueue === null) return warn(WUJIE_TIPS_REPEAT_RENDER);
Expand Down

0 comments on commit 1181351

Please sign in to comment.