Skip to content

fix: skip iframe html and body in visible area#624

Open
PinkChampagne17 wants to merge 1 commit into
react-component:masterfrom
PinkChampagne17:fix-iframe-visible-area
Open

fix: skip iframe html and body in visible area#624
PinkChampagne17 wants to merge 1 commit into
react-component:masterfrom
PinkChampagne17:fix-iframe-visible-area

Conversation

@PinkChampagne17
Copy link
Copy Markdown

@PinkChampagne17 PinkChampagne17 commented Jun 2, 2026

Fix #623.

Summary by CodeRabbit

修复

  • 优化了可见区域计算中对滚动容器根元素的检测方式

测试

  • 新增 iframe 元素的测试用例,确保框架内的根元素被正确跳过

Co-authored-by: Codex <codex@openai.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cfb69bf9-561b-4379-b32c-503b32911597

📥 Commits

Reviewing files that changed from the base of the PR and between 220358d and 1253e1f.

📒 Files selected for processing (2)
  • src/util.ts
  • tests/flip.test.tsx

Walkthrough

修复了 getVisibleArea 函数对页面根元素(HTML/BODY)的检测方式,改用 tagName 字符串比较而非 instanceof 操作符,使其能正确处理 iframe 文档中的元素。新增测试用例验证 iframe 元素不再影响可见区域计算。

Changes

根元素检测修复

Layer / File(s) Summary
根元素检测和 iframe 验证
src/util.ts, tests/flip.test.tsx
getVisibleArea 中将根元素判断条件从 instanceof HTMLBodyElement || instanceof HTMLHtmlElement 改为 tagName === 'BODY' || tagName === 'HTML',避免 instanceof 在跨 iframe 文档时的失效;新增测试用例创建 iframe 并验证其 documentElement 与 body 被正确跳过。

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 一只兔子修缮代码,
tagName 取代 instanceof 的忧虑,
iframe 不再是荆棘丛生,
可见区域从此清晰无误。✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确描述了主要改动:修复iframe中html和body元素在可见区域计算中的跳过逻辑。
Linked Issues check ✅ Passed 代码变更解决了issue #623的核心问题:通过将instanceof检查改为tagName字符串比较,使iframe文档中的html和body元素能被正确识别和跳过。
Out of Scope Changes check ✅ Passed 所有变更都与修复iframe可见区域计算问题相关,包括src/util.ts中的判断逻辑改进和tests/flip.test.tsx中的针对性测试用例,无超出范围的变更。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/util.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

tests/flip.test.tsx

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the getVisibleArea utility to check elements by their tagName ('BODY' or 'HTML') instead of using instanceof checks, which helps handle elements from different contexts like iframes. A corresponding test case has been added to verify this behavior. The reviewer suggested making the tag name comparison case-insensitive by converting tagName to uppercase to ensure compatibility with XML or XHTML documents.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/util.ts
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.

Does not work when rendered inside an iframe

1 participant