fix: prevent stack overflow in nested iframe scenarios#1683
Open
laogong5i0 wants to merge 3 commits intojd-opensource:devfrom
Open
fix: prevent stack overflow in nested iframe scenarios#1683laogong5i0 wants to merge 3 commits intojd-opensource:devfrom
laogong5i0 wants to merge 3 commits intojd-opensource:devfrom
Conversation
feat: undate a version about micro-app
Fixed circular reference issue in getElementQueryTarget function that caused "Maximum call stack size exceeded" errors in multi-level nested iframe applications. Problem: When using iframe sandbox mode with three-layer nesting (A→B→C), accessing document.body in getElementQueryTarget triggered the proxied getter, which called querySelector, leading to infinite recursion: document.body getter → querySelector → getElementQueryTarget → document.body Solution: Use globalEnv.rawDocument.body/head instead of document.body/head to avoid triggering proxied getters and prevent circular calls. Changes: - src/source/patch.ts: Modified getElementQueryTarget to use rawDocument Tested in three-layer nested scenario with iframe sandbox mode.
8218e3f to
677dd2f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
相关 Issue
Fixes #1575
问题描述
在使用 iframe 沙箱模式进行三层嵌套(主应用 A → 子应用 B → 子应用 C)时,出现 "Maximum call stack size exceeded" 错误,导致应用无法正常加载。
问题原因
在
getElementQueryTarget函数(src/source/patch.ts:479-492)中,直接访问document.body和document.head触发了被代理的 getter,导致循环调用:document.body getter → querySelector → getElementQueryTarget → document.body解决方案
使用
globalEnv.rawDocument.body/head替代document.body/head,避免触发被代理的 getter,防止循环调用。测试验证
已在三层嵌套场景下测试验证:
修改文件
src/source/patch.ts: 修改 getElementQueryTarget 函数使用 rawDocument