mirror of
https://github.com/stashapp/stash.git
synced 2026-05-09 05:05:29 +02:00
fix(ui): use path-equality guard to prevent duplicate wall history entries
Replace the 100ms timestamp-based dedup with a path-equality check against history.location. The previous approach relied on Date.now() precision, which varies by browser (Firefox reduces precision to 2ms default / 100ms strict per the spec) and introduced an arbitrary threshold. Since react-router's history.push updates location synchronously, the second dispatch from react-photo-gallery sees the post-push URL and the guard correctly no-ops. Per review feedback on #6829 from @Gykes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2ac751f928
commit
81df9ea997
2 changed files with 11 additions and 11 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { Form } from "react-bootstrap";
|
||||
import * as GQL from "src/core/generated-graphql";
|
||||
import Gallery, {
|
||||
|
|
@ -245,13 +245,13 @@ const MarkerWall: React.FC<IMarkerWallProps> = ({
|
|||
|
||||
// Guard against duplicate clicks - react-photo-gallery can dispatch
|
||||
// the onClick handler twice for a single click event
|
||||
const lastClickTime = useRef(0);
|
||||
const onClick = useCallback(
|
||||
(event, { index }) => {
|
||||
const now = Date.now();
|
||||
if (now - lastClickTime.current < 100) return;
|
||||
lastClickTime.current = now;
|
||||
history.push(photos[index].link);
|
||||
const link = photos[index].link;
|
||||
const current = history.location.pathname + history.location.search;
|
||||
if (current !== link) {
|
||||
history.push(link);
|
||||
}
|
||||
},
|
||||
[history, photos]
|
||||
);
|
||||
|
|
|
|||
|
|
@ -260,13 +260,13 @@ const SceneWall: React.FC<ISceneWallProps> = ({
|
|||
|
||||
// Guard against duplicate clicks - react-photo-gallery can dispatch
|
||||
// the onClick handler twice for a single click event
|
||||
const lastClickTime = useRef(0);
|
||||
const onClick = useCallback(
|
||||
(event, { index }) => {
|
||||
const now = Date.now();
|
||||
if (now - lastClickTime.current < 100) return;
|
||||
lastClickTime.current = now;
|
||||
history.push(photos[index].link);
|
||||
const link = photos[index].link;
|
||||
const current = history.location.pathname + history.location.search;
|
||||
if (current !== link) {
|
||||
history.push(link);
|
||||
}
|
||||
},
|
||||
[history, photos]
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue