Skip to content

perf(clerk-js): Replace unsafe metadata in user.update() with a single PUT - #10979

Merged
nikosdouvlis merged 2 commits into
mainfrom
nikos/user-update-put-metadata
Nov 26, 2026
Merged

nikosdouvlis merged 2 commits into
mainfrom
nikos/user-update-put-metadata

Conversation

@nikosdouvlis

@nikosdouvlis nikosdouvlis commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

user.update({ unsafeMetadata }) now replaces metadata with a single PUT /me/metadata. It no longer reloads the user and diffs on the client. This follows BAPI, where PATCH /metadata merges and PUT /metadata replaces.

 user.update({ unsafeMetadata, ...rest })
   if rest: PATCH /me { ...rest }
-  else:    GET /me                                      (reload)
-  patch = computeMergePatch(this.unsafeMetadata, unsafeMetadata)
-  if patch is empty: return
-  PATCH /me/metadata { unsafe_metadata: patch }        (merge)
+  PUT /me/metadata { unsafe_metadata: unsafeMetadata } (replace)
 packages/clerk-js/
 ├── src/core/resources/User.ts
-├── src/utils/mergePatch.ts          # only user of dequal
-└── package.json: dequal

user.updateMetadata() (merge) is unchanged.

Evidence

  • Before: a metadata-only update() sends 2 requests: GET /me, then PATCH /me/metadata with a computed patch. Seen in production at 3 requests per write when the app also reloads first.
    After: User.test.ts › replaces metadata-only updates with a single PUT /me/metadata
    user = { theme: 'dark', layout: 'compact' }
    await user.update({ unsafeMetadata: { theme: 'light' } })
    expect fetch called once: PUT /me/metadata { unsafeMetadata: '{"theme":"light"}' }
    expect user.unsafeMetadata == PUT response
    
    User.test.ts: 29 passed. integration/tests/unsafeMetadata.test.ts assertions are unchanged; only its comments are updated.

Merge Danger

Door: two-way

Reverting restores the reload-and-diff path. Nothing is persisted differently by the client itself.

Blast Radius: every user.update({ unsafeMetadata }) call

  • Needs FAPI PUT /v1/me/metadata: shipped in clerk/clerk_go#24614 (staging and production). It returns the full user and replaces via userMetadataService.Replace, which skips the write and the webhook when nothing changes.
  • null values: keys set to null are stored as null instead of being removed, matching user.update() before 6.16.1. Noted in the changeset.

@vercel

vercel Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
clerk-js-sandbox Ready Ready Preview Nov 25, 2026 11:11am UTC
swingset Ready Ready Preview Nov 25, 2026 11:11am UTC
1 Skipped Deployment
Project Deployment Actions Updated
mosaic-docs Ignored Ignored Preview Nov 25, 2026 11:11am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: be18102

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

This PR includes changesets to release 4 packages
Name Type
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/electron Patch
@clerk/expo 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

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

User.update now sends supplied unsafeMetadata to /metadata with PUT, without reloading the user or computing a merge patch. When other parameters are also supplied, it patches those first. The merge-patch helper, its tests, and the dequal runtime dependency are removed. Updated tests and a changeset describe metadata replacement and key removal by omission.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: brunol95, wobsoriano

Merge Risk: Low · up to be181 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: user.update() with unsafeMetadata now sends a single PUT instead of a reload-and-diff PATCH flow. It also gives the package scope and a perf label, which matches the r…
Description check Passed The description states the change to user.update({ unsafeMetadata }): it now sends one PUT /me/metadata and no longer reloads or diffs on the client. It also covers the removed dequal dependency, the …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: user.update() with unsafeMetadata now sends a single PUT instead of a reload-and-diff PATCH flow. It also gives the package scope and a perf label, which matches the removed reload and merge-patch computation. The title is a single line of 10 words and does not use vague terms.

Full details: Description check

Explanation

The description states the change to user.update({ unsafeMetadata }): it now sends one PUT /me/metadata and no longer reloads or diffs on the client. It also covers the removed dequal dependency, the test evidence, the FAPI dependency, the null-value behavior, and the revert path. This directly describes the changeset.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Linked repositories: This review skipped 6 repositories. Cross-repository analysis may be incomplete. Check linked repository access and settings.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7716437 and be18102.

Files ignored due to path filters: 1

  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing: 7

  • .changeset/user-update-put-metadata.md
  • integration/tests/unsafeMetadata.test.ts
  • packages/clerk-js/package.json
  • packages/clerk-js/src/core/resources/User.ts
  • packages/clerk-js/src/core/resources/__tests__/User.test.ts
  • packages/clerk-js/src/utils/__tests__/mergePatch.test.ts
  • packages/clerk-js/src/utils/mergePatch.ts
Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

Files with no reviewable changes: 2

  • packages/clerk-js/src/utils/tests/mergePatch.test.ts
  • packages/clerk-js/src/utils/mergePatch.ts

Included review availability: This review used your included allowance. 9 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 10 reviews per hour.

@pkg-pr-new

pkg-pr-new Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@10979

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@10979

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@10979

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@10979

@clerk/electron

npm i https://pkg.pr.new/@clerk/electron@10979

@clerk/electron-passkeys

npm i https://pkg.pr.new/@clerk/electron-passkeys@10979

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@10979

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@10979

@clerk/expo-biometrics

npm i https://pkg.pr.new/@clerk/expo-biometrics@10979

@clerk/expo-google-signin

npm i https://pkg.pr.new/@clerk/expo-google-signin@10979

@clerk/expo-native-components

npm i https://pkg.pr.new/@clerk/expo-native-components@10979

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@10979

@clerk/express

npm i https://pkg.pr.new/@clerk/express@10979

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@10979

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@10979

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@10979

@clerk/mosaic

npm i https://pkg.pr.new/@clerk/mosaic@10979

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@10979

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@10979

@clerk/react

npm i https://pkg.pr.new/@clerk/react@10979

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@10979

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@10979

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@10979

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@10979

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@10979

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@10979

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@10979

commit: be18102

@github-actions

Copy link
Copy Markdown
Contributor

API Changes Report

Generated by Break Check on 2026-11-26T08:21:43.156Z

Summary

Metric Count
Packages analyzed 20
Packages with changes 0
🔴 Breaking changes 0
🟡 Non-breaking changes 0
🟢 Additions 0

No API Changes Detected

All packages have stable APIs with no detected changes.


Report generated by Break Check

Last ran on be18102.

@blacksmith-sh

blacksmith-sh Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Matches Metadata-only user.update() sends one PUT

One PUT /v1/me/metadata with the full new metadata replaced the GET /v1/me plus PATCH merge patch; user.unsafeMetadata ended as {theme:'light'}.

Merge-base

Metadata-only update

This PR be181024

Metadata-only update

Also checked · 4 match

Matches Mixed update: PATCH /me then PUT /me/metadata
Matches Null keys are sent as null in the PUT
Matches Unchanged metadata still sends one PUT
Matches user.updateMetadata() still merges via PATCH

Proof on be181024 · mocked: Clerk Frontend API (MSW mock packages/clerk-js/sandbox/scenarios/proof-unsafe-metadata.ts answers /v...) · Did Proof get it right? Yes · No

View full Proof report · React 👎 or comment @codesmith dismiss this proof to dismiss

@nikosdouvlis
nikosdouvlis enabled auto-merge (squash) November 26, 2026 08:32
@nikosdouvlis
nikosdouvlis merged commit c64d559 into main Nov 26, 2026
141 of 143 checks passed
@nikosdouvlis
nikosdouvlis deleted the nikos/user-update-put-metadata branch November 26, 2026 08:32

This branch was successfully deployed

2 active deployments
Preview – swingset — be181024 Deployed Nov 25, 2026 by vercel[bot]
Preview – clerk-js-sandbox — be181024 Deployed Nov 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant