Skip to content

fix(core): ignore suggestion menu scrolls from another realm - #3398

Open
theluckystrike wants to merge 1 commit into
TypeCellOS:mainfrom
theluckystrike:fix/suggestion-menu-scroll-iframe
Open

theluckystrike wants to merge 1 commit into
TypeCellOS:mainfrom
theluckystrike:fix/suggestion-menu-scroll-iframe

Conversation

@theluckystrike

@theluckystrike theluckystrike commented Nov 22, 2026 •

Copy link
Copy Markdown

Summary

Fixes #3382. The suggestion menu scroll handler now ignores a scroll of the menu itself when the event target comes from another JavaScript realm, such as a same-origin iframe that host-page code manages.

Rationale

SuggestionMenuView.handleScroll skipped scrolls whose target does not contain the decoration, but only when event.target instanceof Node. A node from an iframe's document is not an instance of the host page's Node, so the check was false, the filter was skipped, and a scroll inside the menu moved the menu's reference position.

Changes

  • The guard checks that the target has a contains function instead of using instanceof Node. A Window target still falls through and updates the position, as before.

Impact

None for the normal same-document case. Scrolling an ancestor of the decoration still updates the position.

Testing

  • New unit test in SuggestionMenu.test.ts: it opens the menu, then dispatches a scroll whose target is a node created by an iframe's document, then a scroll on document.body. On main the first scroll causes 1 update (expected 0). With the fix it causes 0 and the body scroll causes 1.
  • vp test run in packages/core: 124 files, all pass.
  • vp lint --type-aware and vp fmt --check on the changed files, and tsc --noEmit -p packages/core/tsconfig.json: clean.

Checklist

  • Code follows the project's coding standards.
  • Unit tests covering the new feature have been added.
  • All existing tests pass.
  • The documentation has been updated to reflect the new feature (not needed)

Summary by CodeRabbit

  • Bug Fixes
    • Suggestion menus now correctly evaluate scroll events from same-origin iframes, while continuing to ignore events from targets that don’t contain the suggestion.

The scroll guard used the host page's Node constructor, so a scroll
event whose target came from a same-origin iframe skipped the filter
and repositioned the menu. Check for contains() instead.
@vercel

vercel Bot commented Nov 22, 2026

Copy link
Copy Markdown

@theluckystrike is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The suggestion-menu scroll handler now checks whether an event target contains the suggestion decoration without requiring the target to be an instance of the current realm’s Node. A test covers scroll events from a same-origin iframe menu and from document.body.

Changes: Suggestion-menu scroll filtering

Layer / File(s) Summary
Realm-independent scroll containment
packages/core/src/extensions/SuggestionMenu/SuggestionMenu.ts, packages/core/src/extensions/SuggestionMenu/SuggestionMenu.test.ts
handleScroll checks for a target with a callable contains method and ignores targets that do not contain the suggestion decoration. The test checks that an iframe menu scroll does not update the store, while a body scroll does.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: yousefed, matthewlipski

Merge Risk: Minimal · up to 3cfbb

This change makes suggestion-menu scroll filtering work for editors embedded in same-origin iframes. Scrolling ancestors of the decoration still updates the menu position. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix and its scope: suggestion menu scroll events from another realm are now ignored. It matches the changeset, which changes the handleScroll guard from an instanceof Node check to…
Description check Passed The description follows the repository template. It has a Summary that states the fix and links issue #3382, a Rationale that explains the instanceof Node failure for iframe nodes, a Changes section, …
Linked Issues check Passed Issue #3382 requires that a scroll inside the suggestion menu be ignored when the menu is in a same-origin iframe, and that an ancestor scroll still update the position. The reviewed diff in packages/…
Out of Scope Changes check Passed The whole-PR diff against the merge base bd39cd4 touches two files: SuggestionMenu.ts (the scroll guard, +8/-3 lines, shown in the diff) and SuggestionMenu.test.ts (a regression test for the iframe sc…
Full details: Title check

Explanation

The title names the fix and its scope: suggestion menu scroll events from another realm are now ignored. It matches the changeset, which changes the handleScroll guard from an instanceof Node check to a contains-method check and adds a test for a cross-realm iframe target. It is specific and follows the conventional commit style.

Full details: Description check

Explanation

The description follows the repository template. It has a Summary that states the fix and links issue #3382, a Rationale that explains the instanceof Node failure for iframe nodes, a Changes section, an Impact section, a Testing section with the new unit test and the commands run, and a completed Checklist. The Screenshots/Video and Additional Notes sections are missing. Screenshots are not needed for this change, so this gap is minor.

Full details: Linked Issues check

Explanation

Issue #3382 requires that a scroll inside the suggestion menu be ignored when the menu is in a same-origin iframe, and that an ancestor scroll still update the position. The reviewed diff in packages/core/src/extensions/SuggestionMenu/SuggestionMenu.ts replaces the event.target instanceof Node guard with a check for a callable contains method on the target. A cross-realm iframe node now passes the guard, so target.contains(decorationNode) runs. For a menu node outside the decoration's ancestor chain, this returns false and the handler returns early. A Window target has no contains, so it falls through and updates the position. A null target is also handled. The issue's own requirement is coding-only, and the PR adds a unit test for the iframe case (per the PR description and test summary). The test file was not read directly in this assessment; the test result relies on the author's description and the change summary. The issue states that a full editor/Floating UI integration was not tested, and no such requirement is imposed.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base bd39cd4 touches two files: SuggestionMenu.ts (the scroll guard, +8/-3 lines, shown in the diff) and SuggestionMenu.test.ts (a regression test for the iframe scroll case, +43/-1 lines, per the change summary). Both changes relate directly to the linked issue. No unrelated change was found. The test file content was not read directly, so this assessment is based on the change summary for that file.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit watched the menu scroll,
An iframe’s node passed through the fold.
The handler checked what it contained,
The menu stayed still; the test confirmed.
Then body scrolls refreshed its place,
And rabbit hopped with quiet grace.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bf0d7ffb-1e1d-4ceb-88d8-a3f9ec653bcc
Commits

Reviewing files that changed from the base of the PR and between bd39cd4 and 3cfbb81.

Files selected for processing: 2

  • packages/core/src/extensions/SuggestionMenu/SuggestionMenu.test.ts
  • packages/core/src/extensions/SuggestionMenu/SuggestionMenu.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
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.

Suggestion-menu scroll filter misses elements from a same-origin iframe

1 participant