Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: race conditions in usePersistedDevicePreferences #1575

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

myandrienko
Copy link
Contributor

@myandrienko myandrienko commented Nov 13, 2024

When mounting and unmounting usePersistedDevicePreferences hook in quick succession, the following race conditions can occur:

  1. useApplyDevicePreferences can apply stale preferences, since the effect it runs is async and is not canceled on unmount.
  2. usePersistDevicePreferences can write new device preferences (most likely, the default ones) before they were applied.

This is fixed by adding cancelation to the effect in useApplyDevicePreferences, and by preventing usePersistDevicePreferences from running before useApplyDevicePreferences completes.

@myandrienko myandrienko merged commit 08aacc4 into main Nov 13, 2024
14 checks passed
@myandrienko myandrienko deleted the persisted-preferences-races branch November 13, 2024 13:46
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.

2 participants