Conversation
…insertBefore crash Fixes DRIVE-APP-Q — 800+ events on Android/NL production. The synchronous dispatch() call inside addImage() was firing a Redux state update while useQueue's processItem() had already triggered setProcessedItems(), causing two concurrent React 17 state updates that led to a torn render and a DOM insertBefore() crash. Adding `await Promise.resolve()` before the optimistic dispatch defers it to the next microtask, after React has flushed the current render cycle.
Apiarry
commented
Aug 27, 2026
Apiarry
left a comment
Collaborator
Author
There was a problem hiding this comment.
Requesting review from @gabrieltira — this fixes the React insertBefore DOM crash on drive-app (DRIVE-APP-Q, 800+ events on Android/NL production). One-line fix, full context in the PR description and linked Notion page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Sentry issue: DRIVE-APP-Q — 800+ events, Android / NL production users.
NotFoundError: Failed to execute 'insertBefore' on 'Node'crash in React DOM, triggered during image upload in the drive-app.Root Cause
Inside
addImage(), a synchronousdispatch()call fires an optimistic Redux state update (CREATED_ONE_IMAGE) before the firstawait. This collides with asetProcessedItems()call already in flight fromuseQueue.processItem(), causing two concurrent React 17 state updates that tear the render and crash the DOM reconciler.Fix
Add
await Promise.resolve()before the optimistic dispatch inaddImage(). This yields to the event loop for one microtask, allowing React to finish flushing thesetProcessedItemsrender before the second state update is applied — eliminating the collision entirely.+ await Promise.resolve(); dispatch?.({ type: MonkActionType.CREATED_ONE_IMAGE, payload: { inspectionId: options.inspectionId, image: localImage }, });Investigation notes
Full bug report and root cause analysis: https://www.notion.so/monkvision/Bug-Report-drive-app-React-insertBefore-Crash-DRIVE-APP-Q-3c930e73786e81eea9e2cfaff0b2f31d
Checklist
ImageUploadTypevariants (beauty shot, close-up, video frame, etc.)