fix(ui): prevent duplicate history entry when clicking wall items#6829
fix(ui): prevent duplicate history entry when clicking wall items#6829speckofthecosmos wants to merge 1 commit intostashapp:developfrom
Conversation
Clicking a scene or marker in the wall view pushes two identical history entries, requiring the user to press back twice to return to the wall. This is caused by react-photo-gallery dispatching the onClick handler twice for a single click event. Add a timestamp-based guard to deduplicate clicks within 100ms. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Reproducibility note: This was consistently reproduced on The fix is defensive and low-risk regardless — a 100ms click dedup via |
|
why not use a debounce instead of storing the last click time in the element? |
|
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now#reduced_time_precision This will also break on firefox where the Date.now() precision is 2ms for default reduction and 100 for strict |
Summary
Clicking a scene or marker in the wall view pushes two identical history entries, requiring users to press back twice to return to the wall. This affects both desktop and mobile browsers.
Root Cause
react-photo-gallerydispatches theonClickhandler twice for a single click event when using a customrenderImagecomponent. The existing codebase already documents this behavior atSceneWallPanel.tsx:99:The
onClickhandler was previously removed from the<img>/<video>elements to avoid this, but theSceneWallandSceneMarkerWallcomponents'onClickcallbacks (which callhistory.push) still receive duplicate dispatches from the Gallery component.Evidence
Instrumented
history.pushStateon a running development instance and confirmed:PUSHcalls to the identical URL within 1ms of each otherVIDEOelement (not the footer<Link>)SceneWallItem.handleClick → Gallery.handleClick → SceneWall.onClick → history.pushFix
Adds a timestamp-based guard (
useRef) toSceneWallPanelandSceneMarkerWallPanelthat deduplicateshistory.pushcalls within 100ms. The double dispatch occurs within 1ms, so this threshold is safe for legitimate rapid navigation while preventing the duplicate entry.Files Changed
ui/v2.5/src/components/Scenes/SceneWallPanel.tsx— add click dedup guardui/v2.5/src/components/Scenes/SceneMarkerWallPanel.tsx— same fix + adduseRefimportTest plan
🤖 Generated with Claude Code