Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复异步JavaScript文件加载异常 #188

Merged
merged 2 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/react16/src/Location.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Button from "antd/es/button";
export default class Location extends React.Component {
handleClick() {
if (window.__WUJIE?.degrade || !window.Proxy || !window.CustomElementRegistry) {
window.$wujie.location.href = "https://wujicode.cn/xy/app/prod/official/home";
} else window.location.href = "https://wujicode.cn/xy/app/prod/official/home";
window.$wujie.location.href = "https://wujicode.cn/xy/app/prod/official/index";
} else window.location.href = "https://wujicode.cn/xy/app/prod/official/index";
}
componentDidMount() {
console.log("react16 location mounted")
Expand Down
4 changes: 2 additions & 2 deletions examples/react17/src/Location.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Button from "antd/es/button";
export default class Location extends React.Component {
handleClick() {
if (window.__WUJIE?.degrade || !window.Proxy || !window.CustomElementRegistry) {
window.$wujie.location.href = "https://wujicode.cn/xy/app/prod/official/home";
} else window.location.href = "https://wujicode.cn/xy/app/prod/official/home";
window.$wujie.location.href = "https://wujicode.cn/xy/app/prod/official/index";
} else window.location.href = "https://wujicode.cn/xy/app/prod/official/index";
}

componentDidMount() {
Expand Down
2 changes: 1 addition & 1 deletion examples/react17/src/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "antd/es/button/style/css";
export default class Location extends React.Component {
state = { count: 10 };
handleClick() {
window.location.href = "https://wujicode.cn/xy/app/prod/official/home";
window.location.href = "https://wujicode.cn/xy/app/prod/official/index";
}

componentDidMount() {
Expand Down
2 changes: 1 addition & 1 deletion examples/vite/src/views/Location.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default {
},
methods: {
handleClick() {
window.$wujie.location.href = "https://wujicode.cn/xy/app/prod/official/home";
window.$wujie.location.href = "https://wujicode.cn/xy/app/prod/official/index";
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions examples/vue2/src/views/Location.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export default {
methods: {
handleClick() {
if (window.__WUJIE?.degrade || !window.Proxy || !window.CustomElementRegistry) {
window.$wujie.location.href = "https://wujicode.cn/xy/app/prod/official/home";
} else window.location.href = "https://wujicode.cn/xy/app/prod/official/home";
window.$wujie.location.href = "https://wujicode.cn/xy/app/prod/official/index";
} else window.location.href = "https://wujicode.cn/xy/app/prod/official/index";
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions examples/vue3/src/views/Location.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export default {
methods: {
handleClick() {
if (window.__WUJIE?.degrade || !window.Proxy || !window.CustomElementRegistry) {
window.$wujie.location.href = "https://wujicode.cn/xy/app/prod/official/home";
} else window.location.href = "https://wujicode.cn/xy/app/prod/official/home";
window.$wujie.location.href = "https://wujicode.cn/xy/app/prod/official/index";
} else window.location.href = "https://wujicode.cn/xy/app/prod/official/index";
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions packages/wujie-core/__test__/integration/href.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("main react location href test", () => {
await triggerClickByJsSelector(page, (appInfo as LooseObject).routeNavSelector);
await appInfoRouteMountedPromise;
await triggerClickByJsSelector(page, (appInfo as LooseObject).routeJumpButtonSelector);
await page.waitForSelector("iframe[src='https://wujicode.cn/xy/app/prod/official/home']");
await page.waitForSelector("iframe[src='https://wujicode.cn/xy/app/prod/official/index']");
await page.goBack();
await page.waitForSelector("wujie-app");
})
Expand All @@ -50,7 +50,7 @@ describe("main vue location href test", () => {
await triggerClickByJsSelector(page, (appInfo as LooseObject).routeNavSelector);
await appInfoRouteMountedPromise;
await triggerClickByJsSelector(page, (appInfo as LooseObject).routeJumpButtonSelector);
await page.waitForSelector("iframe[src='https://wujicode.cn/xy/app/prod/official/home']");
await page.waitForSelector("iframe[src='https://wujicode.cn/xy/app/prod/official/index']");
await page.goBack();
await page.waitForSelector("wujie-app");
})
Expand Down
5 changes: 3 additions & 2 deletions packages/wujie-core/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,12 @@ function rewriteAppendOrInsertChild(opts: {
const { src, text, type, crossOrigin } = element as HTMLScriptElement;
// 排除js
if (!isMatchUrl(src, getEffectLoaders("jsExcludes", plugins))) {
const execScript = (scriptResult) => {
const execScript = (scriptResult: ScriptObject) => {
// 假如子应用被连续渲染两次,两次渲染会导致处理流程的交叉污染
if (sandbox.iframe === null) return warn(WUJIE_TIPS_REPEAT_RENDER);
insertScriptToIframe(scriptResult, sandbox.iframe.contentWindow);
manualInvokeElementEvent(element, "load");
// 只有外联转内联才需要手动触发load
if (scriptResult.content) manualInvokeElementEvent(element, "load");
element = null;
};
const scriptOptions = {
Expand Down