Skip to content

Conversation

mattcosta7
Copy link
Contributor

@mattcosta7 mattcosta7 commented Dec 9, 2023

related to https://github.com/github/primer/issues/2927

Changelog

Ensure theme syncs between initial render and setting up listeners in useEffect. This should handle the unlikely but possible scenario that in between initial render and the effect, the user's preference for theme color has changed. This team is not large, but potentially happens for users who use automatic theme switching based on time/schedule

New

Changed

ThemeProvider setColorMode gets called when setting up subscription

Removed

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

It's not super straightforward to validate, but generally, when setting up subscriptions in an efffect, it's important to ensure that the time between render and the effect was accounted for.

In this case, I believe that occasionally when this effect occurs far enough after that initial render, the match state can change prior to listening to the change event, leading to some ui tearing.

see: useSyncExternalStore's shim implementation (which is basically a subscription to an event) - https://github.com/facebook/react/blob/40f653d13c363c6f81b13de67ce391991fb1f870/packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js#L103-L122

Merge checklist

Copy link

changeset-bot bot commented Dec 9, 2023

🦋 Changeset detected

Latest commit: 4b33f0f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mattcosta7 mattcosta7 changed the title sync theme once Sync color mode prior to subscribing in ThemeProvider Dec 9, 2023
@mattcosta7 mattcosta7 marked this pull request as ready for review December 9, 2023 14:16
@mattcosta7 mattcosta7 requested review from a team and pksjce December 9, 2023 14:16
@mattcosta7 mattcosta7 self-assigned this Dec 9, 2023
Copy link
Contributor

github-actions bot commented Dec 9, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 105.19 KB (+0.02% 🔺)
dist/browser.umd.js 105.73 KB (+0.03% 🔺)

@mattcosta7 mattcosta7 added this pull request to the merge queue Dec 11, 2023
@mattcosta7
Copy link
Contributor Author

gh/gh integration tests are 🟢

Merged via the queue into main with commit 21e75dd Dec 11, 2023
@mattcosta7 mattcosta7 deleted the sync-color-mode-once-at-least branch December 11, 2023 19:29
@primer primer bot mentioned this pull request Dec 11, 2023
@primer primer bot mentioned this pull request Dec 19, 2023
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.

3 participants