Skip to content

Commit 6c1753f

Browse files
authored
Assign new handlerTag each time handler is created (#3453)
## Description A while ago we fixed a problem where Gesture Handler was crashing on `StrictMode`. However, it seems to have broken old API. >[!TIP] > Check [this PR](#3247) for context ### Problem The problem lies in difference between old and new API. In new API, anytime handler is created, it is assigned new `handlerTag`. So in `StrictMode`, we would have the following order: ``` attach 1 drop 1 attach 2 ``` Basically handler with tag `1` was created, then dropped, and new handler took its place. When old API is used, `handlerTag` stays the same. However, because we do not reattach handler if given tag has been dropped, second attach effectively doesn't work. ### Solution In order to fix that, we assign new `handlerTag` each time `createGestureHandler` is created, Therefore logic with `droppedHandlers` is the same in case of both APIs. Fixes #3450 ## Test plan Tested on the code from linked issue
1 parent 97147c1 commit 6c1753f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/handlers/createHandler.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export default function createHandler<
186186
static displayName = name;
187187
static contextType = GestureHandlerRootViewContext;
188188

189-
private handlerTag: number;
189+
private handlerTag = -1;
190190
private config: Record<string, unknown>;
191191
private propsRef: React.MutableRefObject<unknown>;
192192
private isMountedRef: React.MutableRefObject<boolean | null>;
@@ -196,7 +196,6 @@ export default function createHandler<
196196

197197
constructor(props: T & InternalEventHandlers) {
198198
super(props);
199-
this.handlerTag = getNextHandlerTag();
200199
this.config = {};
201200
this.propsRef = React.createRef();
202201
this.isMountedRef = React.createRef();
@@ -329,6 +328,7 @@ export default function createHandler<
329328
private createGestureHandler = (
330329
newConfig: Readonly<Record<string, unknown>>
331330
) => {
331+
this.handlerTag = getNextHandlerTag();
332332
this.config = newConfig;
333333

334334
RNGestureHandlerModule.createGestureHandler(

0 commit comments

Comments
 (0)