fix(authoring): context menu flickers at previous position - #451
Conversation
📝 WalkthroughWalkthroughChangesContext menu event handling
Estimated code review effort: 2 (Simple) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Description checkExplanation The description includes the required Issue, Solution, Risk, and Checklist sections. It explains the stale adjustedPosition issue and the useLayoutEffect solution. Some checklist items remain unchecked, but the description is mostly complete. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
harbassan
left a comment
There was a problem hiding this comment.
Virtual.Patient.System.-.UoA.Mozilla.Firefox.2026-07-27.23-38-02.mp4
There was a problem hiding this comment.
Screencast_20260727_235200.webm
it is working for me idk hartej, im on firefox browser
the other sort of flicker thats happening seems to be from the previous context menu location so could not be closing properly or smthn like that
|
yeah i think that tiny flicker you have at the start of your video is the one im having all the time, where there is a render that happens at the previous location before a rerender at the new location. |
The adjusted position was kept in state but never cleared when the menu closed, so reopening it painted one frame at the previous menu's coordinates. The correction also ran in useEffect, i.e. after paint, so that wrong frame was visible. Move the measurement to useLayoutEffect so it lands before paint, and reset the stored position when the menu unmounts. Claude-Session: https://claude.ai/code/session_01YDsqKXLrLfr6u22sh1VFFx
Issue
The main cause for the flicker is that, the current function which create the context menu check onmouseup if your cursor is on a piece of html which is apart of the context menu. This bug happens when you are holding right click and move your cursor off the context menu and release right click.adjustedPositionis never cleared when the menu closes so the next open paints one frame at the previous menu's coordinates before the effect corrects itSolution
Change from mouseup to mousedown because it is guaranteed that the mouse will start on top of the context menu due to negative offsetuseLayoutEffectto adjust first before paintRisk
NONE
Checklist
Summary by CodeRabbit