refactor(js): extract a generic store from TokenCache#8860
Conversation
Lock in current cross-tab, lifecycle, degradation, and audience-keying behavior as the regression bar for the TokenCache decoupling (SDK-117). The broadcast postMessage-failure case is a known pre-existing bug (SDK-119), captured as an it.fails tripwire.
Lift the raw key/value storage out of MemoryTokenCache into a small generic createTokenStore<V> (pure storage: no timers, no BroadcastChannel, no JWT knowledge) and rewire the cache onto it. No behavior change; the identity-based deleteKey guard and overwrite check are preserved. First structural step of SDK-117.
🦋 Changeset detectedLatest commit: 48ccda4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types 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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository YAML (base), Repository UI (inherited) Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
First slice of the TokenCache decoupling (SDK-117), in two no-behavior-change steps.
The first commit backfills characterization tests that pin down current cache behavior (cross-tab
close()lifecycle, graceful degradation whenBroadcastChannelis missing, audience key coalescing) to serve as the regression bar for the rest of the refactor. The second lifts the raw key/value storage out ofMemoryTokenCacheinto a small genericcreateTokenStore<V>and rewires the cache onto it, so storage is testable on its own without timers or channel mocks.The part worth a careful read is the
cache.* -> store.*rewire intokenCache.ts. ThedeleteKeyidentity check and the overwrite guard both rely onstore.get(key) !== valuepreserving reference identity, which the Map-backed store does. The fullsrc/coresuite stays green (632 tests, with Session/Client as the real consumers).Writing the backfill surfaced a pre-existing bug: a broadcast
postMessagefailure evicts a freshly cached token, because the throw lands insetInternal's.catch(deleteKey). I left it as anit.failstripwire and filed it separately as SDK-119 (backport candidate) rather than fixing it in this refactor.Empty changeset, since nothing here is user-facing.