fix(editor): prevent duplicate tab when clicking links in read-only view - #9681
fix(editor): prevent duplicate tab when clicking links in read-only view#9681jadhavgaurav wants to merge 1 commit into
Conversation
The custom link extension's click handler calls window.open() but never calls event.preventDefault(). In an editable view ProseMirror suppresses the native anchor click (contenteditable), so only window.open() fires. In a read-only view that suppression doesn't happen, so the native <a target="_blank"> navigation also fires, opening a second identical tab. Fixes makeplane#9386
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe custom link click handler now prevents native anchor navigation before calling ChangesCustom link navigation
Estimated code review effort: 1 (Trivial) | ~5 minutes Merge Risk: ⚪ Minimal · up to This localized change prevents read-only links from opening duplicate tabs by suppressing the browser’s second navigation, with no actionable merge-blocking risk remaining beyond normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description explains the issue, root cause, fix, test limitations, validation steps, and linked issue. It omits the template headings for Type of Change and Screenshots, but the required technical information is present. Full details: Linked Issues checkExplanation The change meets issue ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
Left-clicking a link inside a read-only rendered comment or work-item
description (e.g. a PR URL) opens it in two identical tabs instead of one.
Editable mode is unaffected.
Root cause
clickHandler.ts's ProseMirror click handler callswindow.open(href, target)but never calls
event.preventDefault(). In an editable view, ProseMirrorsuppresses the native anchor click (the editor is
contenteditable), so onlywindow.open()fires. In a read-only view that suppression doesn'thappen, so the native
<a target="_blank">navigation also fires — one tabfrom
window.open(), a second from the browser following the anchor itself.Fix
Call
event.preventDefault()beforewindow.open(), so the native anchornavigation is suppressed in both editable and read-only modes. One line.
Tests
packages/editorcurrently has no test runner configured (notestscript,no vitest/jest dependency — unlike
apps/live/packages/codemods, which dohave vitest set up). Adding a test harness to this package is out of scope
for a one-line fix, so I didn't bootstrap one. I verified by tracing the
exact code path:
event.button !== 0already short-circuits non-left-clicks(explaining why middle-click already worked), and the added
preventDefault()sits in the only branch that callswindow.open(), beforethe return that lets the click bubble.
oxlinton the changed file — clean.oxfmt --checkon the changed file — clean.pnpm check:typesinpackages/editor— no new errors introduced (thepackage currently fails to type-check on a clean checkout too, with
unrelated
@plane/utils/@plane/types/etc. "cannot find module" errorsfrom unbuilt workspace packages; confirmed identical with and without this
change via
git stash).Related issue
Fixes #9386
Summary by CodeRabbit