Skip to content

Commit

Permalink
fix(iframe): 修复 handler 为 undefined 时执行 addEventListener 错误 (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfred-Skyblue authored Jun 30, 2023
1 parent f9d222c commit 30bf8c1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/wujie-core/src/iframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ function patchIframeHistory(iframeWindow: Window, appHostPath: string, mainHostP
/**
* 动态的修改iframe的base地址
* @param iframeWindow
* @param url
* @param appHostPath
* @param mainHostPath
*/
Expand Down Expand Up @@ -390,10 +389,11 @@ function patchDocumentEffect(iframeWindow: Window): void {
handler: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions
): void {
if (!handler) return;
let callback = handlerCallbackMap.get(handler);
const typeList = handlerTypeMap.get(handler);
// 设置 handlerCallbackMap
if (!callback && handler) {
if (!callback) {
callback = typeof handler === "function" ? handler.bind(this) : handler;
handlerCallbackMap.set(handler, callback);
}
Expand Down Expand Up @@ -600,6 +600,9 @@ export function initBase(iframeWindow: Window, url: string): void {
/**
* 初始化iframe的dom结构
* @param iframeWindow
* @param wujie
* @param mainHostPath
* @param appHostPath
*/
function initIframeDom(iframeWindow: Window, wujie: WuJie, mainHostPath: string, appHostPath: string): void {
const iframeDocument = iframeWindow.document;
Expand Down Expand Up @@ -634,7 +637,7 @@ function stopIframeLoading(iframeWindow: Window) {
return new Promise<void>((resolve) => {
function loop() {
setTimeout(() => {
let newDoc = null;
let newDoc;
try {
newDoc = iframeWindow.document;
} catch (err) {
Expand Down Expand Up @@ -769,7 +772,8 @@ export function insertScriptToIframe(
/**
* 加载iframe替换子应用
* @param src 地址
* @param shadowRoot
* @param element
* @param degradeAttrs
*/
export function renderIframeReplaceApp(
src: string,
Expand Down

0 comments on commit 30bf8c1

Please sign in to comment.