Skip to content

fix: prevent stack overflow in nested iframe scenarios#1683

Open
laogong5i0 wants to merge 3 commits intojd-opensource:devfrom
laogong5i0:fix_iframe_stack_overflow
Open

fix: prevent stack overflow in nested iframe scenarios#1683
laogong5i0 wants to merge 3 commits intojd-opensource:devfrom
laogong5i0:fix_iframe_stack_overflow

Conversation

@laogong5i0
Copy link

@laogong5i0 laogong5i0 commented Feb 28, 2026

相关 Issue

Fixes #1575

问题描述

在使用 iframe 沙箱模式进行三层嵌套(主应用 A → 子应用 B → 子应用 C)时,出现 "Maximum call stack size exceeded" 错误,导致应用无法正常加载。

问题原因

getElementQueryTarget 函数(src/source/patch.ts:479-492)中,直接访问 document.bodydocument.head 触发了被代理的 getter,导致循环调用:document.body getter → querySelector → getElementQueryTarget → document.body

解决方案

使用 globalEnv.rawDocument.body/head 替代 document.body/head,避免触发被代理的 getter,防止循环调用。

测试验证

已在三层嵌套场景下测试验证:

  • ✅ 主应用 A 加载子应用 B(iframe 模式)
  • ✅ 子应用 B 加载子应用 C(iframe 模式)
  • ✅ 无栈溢出错误
  • ✅ 所有应用正常加载和交互

修改文件

  • src/source/patch.ts: 修改 getElementQueryTarget 函数使用 rawDocument

@laogong5i0 laogong5i0 closed this Feb 28, 2026
@laogong5i0 laogong5i0 reopened this Feb 28, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants