Repository navigation
feat(clerk-js): ask fapi for the client only on reload and touch - #10874
Draft
nikosdouvlis wants to merge 2 commits into
Draft
nikosdouvlis wants to merge 2 commits into
nikosdouvlis wants to merge 2 commits into
Conversation
Why: FAPI is adding an API version where GET responses carry the client only when the request has include_client=true. clerk-js already ignores the client on GETs unless forceUpdateClient is set, so it only has to ask where it applies it. What changed: GETs with forceUpdateClient (reload, including Organization.reload) and every session touch send include_client=true. getRoles, getDomains and getInvitations no longer force a client update. The flag came from #2073 and was already dropped from getMemberships in #2082. Context: SUPPORTED_FAPI_VERSION is not bumped here. This must not release before FAPI accepts include_client on the current API version, because today it rejects the unknown param on touch and on GET /v1/organizations/{id}.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 9ef0fbe The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 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 |
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/electron
@clerk/electron-passkeys
@clerk/eslint-plugin
@clerk/expo
@clerk/expo-biometrics
@clerk/expo-google-signin
@clerk/expo-native-components
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/mosaic
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
Why: Once fapi returns the client on focus touches, a focus touch response that lands after a newer response overwrites the newer client with its older one. user.update() reverts, an org switch reverts, and after signOut() the sessions show as active again. A late focus touch also re-set the session cookie after sign-out. What changed: The Client singleton keeps a revision that moves on every write. A focus touch records it when sent and, if it moved by the time the response arrives, the whole response is discarded before it is parsed: no client, no in-place session update, no token emit. The check sits in Session._touchPost because getClientResourceFromPayload writes the singleton at parse time, before Clerk.updateClient runs. All other requests, including setActive touches, apply as before. Context: A dropped focus touch may have been the newer one. The write that superseded it carried a full client, so only a change made elsewhere in between is missed until the next focus.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Draft. Do not merge until fapi accepts
include_clienton the current API version in production. clerk-js is hot-loaded, and today fapi rejects the unknown param on session touch and onGET /v1/organizations/{id}.fapi is adding an API version where GET responses carry the client only when the request asks for it with
include_client=true. clerk-js already ignores the client on GETs unlessforceUpdateClientis set, so it only needs to ask where it applies it.Behavior change: listing organization roles, domains or invitations no longer refreshes the client. The flag was added in #2073 and dropped from
getMembershipstwo days later in #2082. A role change made elsewhere now shows up on the next mutation,setActiveor focus touch.Focus touch guard: once fapi returns the client on focus touches, a focus touch response that lands after a newer response would overwrite the newer client with its older one.
user.update()reverts, an org switch reverts, and aftersignOut()the sessions show as active again. The client now keeps a revision that moves on every write. A focus touch records it when sent, and its whole response is dropped if the revision moved by the time it arrives.The check sits in
Session._touchPostbecausegetClientResourceFromPayloadwrites the client singleton at parse time, beforeClerk.updateClientruns. Every other request applies as before, includingsetActivetouches, so nothing the user did is ever dropped. A dropped focus touch may have been the newer one. The write that superseded it carried a full client, so only a change made elsewhere in between is missed until the next focus. This also stops a late focus touch from setting the session cookie again after sign-out, which happens today.Checked in a browser against a dev instance with the new fapi behavior emulated. With the focus touch response held,
user.update(), the org switch, email verification and sign-out all reverted before the guard and hold with it. With today's fapi the focus touch still refreshes the session cookie.SUPPORTED_FAPI_VERSIONis not bumped here, so nothing changes in what fapi returns yet. The bump follows once the new version is registered.Not run on a device. Native OAuth and SSO finish with
signIn.reload({ rotatingTokenNonce }), which now carries both the nonce andinclude_client=true(covered by a unit test).Refs SDK-172, PLAT-4577
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change