javascript icon indicating copy to clipboard operation
javascript copied to clipboard

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

Open panteliselef opened this issue 1 year ago • 1 comments

Description

Alternative solution to #3091 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 Apr 05 '24 08:04 panteliselef

🦋 Changeset detected

Latest commit: dc6d78c7859af282dd384d273c7dcbdc5183e0ed

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

This PR includes changesets to release 14 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/fastify Patch
@clerk/nextjs Patch
@clerk/remix Patch
@clerk/clerk-sdk-node Patch
gatsby-plugin-clerk Patch
@clerk/localizations 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 Apr 05 '24 08:04 changeset-bot[bot]

Closing this as backporting this to v4 is not a priority at the moment

panteliselef avatar May 27 '24 14:05 panteliselef