Skip to content

Prevent links from opening twice in read-only mode#9404

Open
nicksan222 wants to merge 2 commits into
makeplane:previewfrom
nicksan222:fix/9386-read-only-link-double-open
Open

Prevent links from opening twice in read-only mode#9404
nicksan222 wants to merge 2 commits into
makeplane:previewfrom
nicksan222:fix/9386-read-only-link-double-open

Conversation

@nicksan222

@nicksan222 nicksan222 commented Jul 12, 2026

Copy link
Copy Markdown

Description

Fixes duplicate tabs opening when left-clicking links in read-only comments and work-item descriptions.

The custom link click handler previously called window.open() even when the editor was read-only. In that mode, the browser also followed the rendered anchor's native navigation, causing the same link to open twice. The handler now returns early for non-editable views, allowing the browser to handle read-only links natively while preserving the existing programmatic behavior in editable views.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Not applicable.

Test Scenarios

  • Verified that the custom click handler returns without calling window.open() when the editor is read-only, leaving navigation to the native anchor behavior.
  • Verified that the focused regression test fails before the fix and passes after it.
  • Ran formatting and lint checks against the changed code.

References

Fixes #9386

Summary by CodeRabbit

  • Bug Fixes
    • Improved link-click handling to reliably identify the clicked link and only process it when the link is within the editor’s active content area.
    • Prevented link clicks from being processed when the editor is in a non-editable state, avoiding unintended opening behavior.
    • Stopped navigation/opening for unsafe URL schemes (such as javascript:, data:, vbscript:, file:, or about:) to reduce the risk of unintended actions.

Copilot AI review requested due to automatic review settings July 12, 2026 17:34
@CLAassistant

CLAassistant commented Jul 12, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bc9bebb0-7f21-4429-9106-7d55e923f179

📥 Commits

Reviewing files that changed from the base of the PR and between 26a9301 and 295c843.

📒 Files selected for processing (1)
  • packages/editor/src/core/extensions/custom-link/helpers/clickHandler.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/editor/src/core/extensions/custom-link/helpers/clickHandler.ts

📝 Walkthrough

Walkthrough

The custom link click handler resolves contained anchors, blocks dangerous URI schemes, prevents opening in non-editable views, and opens safe links only in editable views.

Changes

Custom link click handling

Layer / File(s) Summary
Link safety and opening flow
packages/editor/src/core/extensions/custom-link/helpers/clickHandler.ts
handleClick resolves the nearest contained anchor, derives its attributes, blocks dangerous schemes with preventDefault(), skips window.open for non-editable views, and opens safe links in editable views.

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

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: fixing duplicate link opens in read-only mode.
Description check ✅ Passed The PR description follows the template and includes the required sections with adequate detail.
Linked Issues check ✅ Passed The change addresses #9386 by stopping the custom handler in read-only views so links open once.
Out of Scope Changes check ✅ Passed The PR only touches the custom link click handler and stays within the linked bug fix scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes duplicate tabs opening when clicking links in read-only rendered editor content by avoiding the custom window.open() click handling in non-editable ProseMirror views.

Changes:

  • Added an early return in the custom-link ProseMirror click handler when view.editable is false to let native anchor navigation handle read-only clicks.

Comment thread packages/editor/src/core/extensions/custom-link/helpers/clickHandler.ts Outdated
@nicksan222 nicksan222 force-pushed the fix/9386-read-only-link-double-open branch 2 times, most recently from a18f728 to de2c79f Compare July 12, 2026 17:54
@nicksan222 nicksan222 force-pushed the fix/9386-read-only-link-double-open branch from de2c79f to 295c843 Compare July 12, 2026 17:55
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.

[bug]: Left-clicking a link in a read-only comment/description opens two tabs

3 participants