feat(backend, clerk-js): Deprecate metadata updates in user update methods#8587
feat(backend, clerk-js): Deprecate metadata updates in user update methods#8587brunol95 wants to merge 9 commits into
Conversation
🦋 Changeset detectedLatest commit: 4cf3a28 The changes in this PR will be included in the next version bump. This PR includes changesets to release 20 packages
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.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR refactors user metadata update paths across the Clerk JavaScript SDK: it deprecates metadata parameters on updateUser/user.update, adds an RFC 7396 computeMergePatch utility, makes frontend User.update async to conditionally route unsafeMetadata via merge-patch-aware updateMetadata (short-circuiting when unchanged), splits backend updateUser into conditional PATCH (non-metadata) and PUT (metadata), and adds replaceUserMetadata for full metadata replacement. Tests and API/version constant bumps accompany the changes. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
…update Co-authored-by: Cursor <cursoragent@cursor.com>
640692b to
16fdd04
Compare
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@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: |
wobsoriano
left a comment
There was a problem hiding this comment.
Left a small suggestion and a question.
Also if possible, I think we should add an e2e test. We can place the test here https://github.com/clerk/javascript/blob/main/integration/tests/unsafeMetadata.test.ts
There was a problem hiding this comment.
Let's split this into separate changesets so each package changelog stays focused 👍🏼
- for backend
- for clerk-js and shared
| }); | ||
| } | ||
|
|
||
| const patch = computeMergePatch(this.unsafeMetadata, unsafeMetadata); |
There was a problem hiding this comment.
Does this preserve replacement semantics if this.unsafeMetadata is not fresh at the moment of the call? Touch-on-focus can refresh the user in common tab-switching flows, but user.update({ unsafeMetadata }) previously sent the caller-provided value as the full replacement regardless of local cache state. With this client-side diff, a stale local value can produce an incomplete patch, or {} and skip the request entirely.
Correct me if Im wrong 😄
There was a problem hiding this comment.
Ah yes you are right . There are two scenarios:
- if we execute the call to PATCH
v1 /meendpoint first that returns a freshuserobject. No issue here since the diff will be using the latest data. - If the request is a metadata only update, then theres a chance the
userobject could be stale. In this case, I think we'll need to perform a reload first.
There was a problem hiding this comment.
@wobsoriano I pushed a fix. Let me know what you think!
wobsoriano
left a comment
There was a problem hiding this comment.
a couple more comments, but this is looking good! Thank you for resolving the other requests
- update changesets - refactor to use dequal pkg - refactor tests to remove type assertion
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.changeset/route-unsafe-metadata-to-merge-endpoint.md:
- Line 13: Fix the broken inline code span by adding the missing opening
backtick so the fragment around user.update({ unsafeMetadata }) is rendered as
an inline code span; locate the sentence containing "user.update({
unsafeMetadata })` continues to work for now..." and prepend a backtick before
user.update to produce `user.update({ unsafeMetadata })` continues to work for
now and preserves its existing full-replacement behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 38c3faa6-142f-4cc3-b7e7-b42ea737c237
📒 Files selected for processing (5)
.changeset/deprecate-update-user-metadata.md.changeset/route-unsafe-metadata-to-merge-endpoint.mdintegration/tests/unsafeMetadata.test.tspackages/clerk-js/src/utils/__tests__/mergePatch.test.tspackages/clerk-js/src/utils/mergePatch.ts
✅ Files skipped from review due to trivial changes (1)
- .changeset/deprecate-update-user-metadata.md
wobsoriano
left a comment
There was a problem hiding this comment.
Thanks for addressing the comments!
I think the main tradeoff I see is that mixed metadata + non-metadata updates are now split into two requests, so they are no longer atomic if the second request fails.
Approving!
https://github.com/clerk/javascript into bruno/user-5312-deprecate-update-user-metadata-fields
|
!snapshot |
Description
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change