javascript icon indicating copy to clipboard operation
javascript copied to clipboard

fix(clerk-js,shared,clerk-react): Use common cache for swr

Open panteliselef opened this issue 1 year ago • 1 comments

Description

Alternative solution to #3091 (but for Core-2) that aims to solve the same issue: How to sync data between hooks and UI components.

A common issue with Clerk so far is that the react hooks that are bundled with a host application will have a different cache than the once used with the bundled UI components from clerk-js.

This PR solves that issue by introducing a single common cache that is created a top level and is passed down to any dependencies.

Scenarios

  1. clerk-react has its own cache and it is passed down to clerk-js via the load method (discarding the clerk-js default cache).
  2. clerk-js is used directly and it uses its own cache.

This ensures that when calling useOrganizationList({memberships:true}) from the host app, if the hook has already run and fetched data due to a UI component having been rendered then this will be a cache hit (if data are not stale). Previous that would be a cache miss.

Checklist

  • [ ] npm test runs as expected.
  • [ ] npm run build runs as expected.
  • [ ] (If applicable) JSDoc comments have been added or updated for any package exports
  • [ ] (If applicable) Documentation has been updated

Type of change

  • [ ] 🐛 Bug fix
  • [ ] 🌟 New feature
  • [ ] 🔨 Breaking change
  • [ ] 📖 Refactoring / dependency upgrade / documentation
  • [ ] other:

panteliselef avatar May 13 '24 12:05 panteliselef

🦋 Changeset detected

Latest commit: 6d335e84e18ef66768c5c9d38c42ae51b98e6bc1

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

This PR includes changesets to release 15 packages
Name Type
@clerk/clerk-js Minor
@clerk/shared Minor
@clerk/clerk-react Minor
@clerk/types Minor
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/backend Patch
@clerk/elements Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/remix Patch
@clerk/clerk-sdk-node Patch
@clerk/testing Patch
@clerk/themes 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

changeset-bot[bot] avatar May 13 '24 12:05 changeset-bot[bot]

A bug in the implementation was discovered, closing and it is fixed, I will reopen.

panteliselef avatar Jun 04 '24 14:06 panteliselef