Skip to content

feat: add createExternalStore utility and ClockProvider (v4 backport)#247

Merged
smarcet merged 3 commits into
v4.xfrom
feature/external-store-clock-context-v4
May 27, 2026
Merged

feat: add createExternalStore utility and ClockProvider (v4 backport)#247
smarcet merged 3 commits into
v4.xfrom
feature/external-store-clock-context-v4

Conversation

@gcutrini
Copy link
Copy Markdown
Contributor

ref: https://app.clickup.com/t/86b8e70g2

Backport of #195 to the v4.x maintenance branch so event-site (currently on uicore 4.2.29) can adopt ClockProvider without committing to a full MUI v5 -> v6 migration up-front.

What's included

  • src/utils/external-store.js — generic createExternalStore factory built on useSyncExternalStore
  • src/components/clock-context.jsClockProvider, useClock, useClockSelector (wraps the existing Clock)
  • New webpack entries: components/clock-context, utils/external-store
  • New exports from src/components/index.js
  • New dep: use-sync-external-store@^1.6.0

Tests

24 new tests (12 for the store factory, 8 for the clock context, 4 misc). Pinned @testing-library/react@^11 for React 16 compatibility (the v5 PR uses v12+). Full suite: 123/123 pass.

Notes

  • React 16 currently; per the readme note, the shim import can be replaced with the native react one when the v5 line moves to React 18.
  • Functionally identical to feat: add createExternalStore utility and ClockProvider #195. The only deltas are the testing-library version pin and the package.json/yarn.lock layout matching v4.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4c98b41e-e50d-418d-a917-2e751940f891

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/external-store-clock-context-v4

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gcutrini gcutrini requested a review from smarcet May 21, 2026 12:35
Backport of #195 to v4.x. Adds a generic external store factory
(createExternalStore) using useSyncExternalStore that lets components
subscribe to frequently-updating data sources without unnecessary
re-renders, plus a pre-built clock store (ClockProvider, useClock,
useClockSelector) wrapping the existing Clock component.

Tests use @testing-library/react@11 for React 16 compatibility.
@gcutrini gcutrini force-pushed the feature/external-store-clock-context-v4 branch from 49de34b to 148bd3c Compare May 26, 2026 14:53
gcutrini added 2 commits May 27, 2026 08:14
…seSyncExternalStoreWithSelector

Delegates selector + equality handling to the react-recommended primitive
from use-sync-external-store. Removes the manual ref bookkeeping, the
null-sentinel ambiguity for cached results, and the useCallback dependency
on isEqual that recreated the snapshot closure on every parent render.
Provider now accepts initialValue so getSnapshot returns a real value
before the first emit. ClockProvider forwards its now prop as
initialValue so consumers reading useClock or useClockSelector during
the initial render see a valid timestamp instead of null.
Copy link
Copy Markdown
Collaborator

@smarcet smarcet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@smarcet smarcet merged commit 325e249 into v4.x May 27, 2026
5 checks passed
@gcutrini gcutrini deleted the feature/external-store-clock-context-v4 branch May 28, 2026 13:39
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