Skip to content

Fix useColorScheme subscription lifecycle - #2853

Open
huytdps13400 wants to merge 1 commit into
necolas:masterfrom
huytdps13400:fix/2848-stable-color-scheme-subscription
Open

huytdps13400 wants to merge 1 commit into
necolas:masterfrom
huytdps13400:fix/2848-stable-color-scheme-subscription

Conversation

@huytdps13400

Copy link
Copy Markdown

Summary

  • keep each useColorScheme Appearance subscription active for the hook lifetime
  • avoid removing and re-adding listeners after unrelated component rerenders
  • add regression coverage for rerender and unmount subscription behavior

Fixes #2848.

Verification

  • focused useColorScheme Jest test: RED before the fix (2 registrations after rerender), GREEN after the fix
  • npm run test: Flow, Prettier, ESLint, 47 DOM suites / 713 tests passed, 3 Node suites / 6 tests passed
  • npm run build -w react-native-web: Flow, ESM, and CommonJS builds passed
  • Chromium runtime: two hook instances retained 2 active listeners with 0 removals after rerender; a simulated prefers-color-scheme flip updated both values from light to dark; console remained clean
  • git diff --check: passed

@codesandbox-ci

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 8f95c1e:

Sandbox Source
react-native-web-examples Configuration

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.

useColorScheme resubscribes on every render; listeners removed mid-dispatch miss prefers-color-scheme changes

1 participant