Skip to content

Re-arm useDebouncedMemo's mounted ref on mount - #1208

Open
theluckystrike wants to merge 1 commit into
glideapps:mainfrom
theluckystrike:fix/debounced-memo-strictmode
Open

theluckystrike wants to merge 1 commit into
glideapps:mainfrom
theluckystrike:fix/debounced-memo-strictmode

Conversation

@theluckystrike

Copy link
Copy Markdown

Fixes #1198.

Under React.StrictMode the mount effect runs, its cleanup runs, and then the effect runs again. useDebouncedMemo set mountedRef to false in the cleanup and never set it back, so the debounced value never updated and the accessibility tree rendered zero cells.

The effect now sets mountedRef to true when it runs, which is the four-line change suggested in the issue. Unmount still stops a pending update.

New tests in test/use-debounced-memo.test.tsx render the hook with and without StrictMode, check that it updates after the debounce, and check that an unmounted hook does not update. The StrictMode test fails on main. The core vitest suite (390 tests), eslint and prettier pass. tsc reports the same errors as main, none in these files.

Under React.StrictMode the mount effect runs, its cleanup runs, then the
effect runs again. useDebouncedMemo set mountedRef to false in the
cleanup and never set it back, so the debounced value never updated and
the accessibility tree rendered zero cells (glideapps#1198).

The effect now sets mountedRef to true when it runs, which is the
four-line change suggested in the issue. Unmount still stops a pending
update.

Tests in test/use-debounced-memo.test.tsx render the hook with and
without StrictMode and check that it updates after the debounce, and
that an unmounted hook does not update. The StrictMode test fails
without this change. The core vitest suite (390 tests), eslint and
prettier pass; tsc reports the same 20 errors as main, none in these
files.

Fixes glideapps#1198

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useDebouncedMemo never re-arms mountedRef: accessibility tree never renders under React StrictMode

1 participant