Skip to content

refactor(mosaic): type machine state names and check targets in setup machines - #10511

Open
alexcarpenter wants to merge 1 commit into
mainfrom
carp/mosaic-machine-state-names
Open

alexcarpenter wants to merge 1 commit into
mainfrom
carp/mosaic-machine-state-names

Conversation

@alexcarpenter

Copy link
Copy Markdown
Member

Description

Types machine state names in the Mosaic machine lib. Runtime behavior does not change.

  • For machines built with setup().createMachine, TStates is inferred from the states keys, so snapshot.value is the union of state names instead of string, and initial plus every transition target are checked against those names.
  • StateMachine, Snapshot, Actor and CreateActorOptions take a TStates param, threaded through createActor, mockActor, useMachine, useActor and useSelector. It defaults to string everywhere, so callers that pass explicit type arguments still compile.
  • initial and targets are wrapped in NoInfer, so a bare createMachine({ initial: 'a', states: { a: { on: { NEXT: 'b' } }, b: {} } }) no longer infers TStates from initial and rejects the valid target 'b'.
  • The actor internals now carry TStates, which removes two as string casts in create-actor.ts (suppression count 8 → 6).

No existing machine needed changes to typecheck. The machine lib is not part of @clerk/mosaic's public exports, so this has an empty changeset.

Checklist

  • pnpm test runs as expected.
  • pnpm 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:

@vercel

vercel Bot commented Oct 29, 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 Oct 29, 2026 12:21am UTC
swingset Ready Ready Preview Oct 29, 2026 12:21am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b94f92f

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

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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 Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between cb8638a and b94f92f.

Files selected for processing: 8
  • .changeset/mosaic-machine-state-names.md
  • packages/mosaic/eslint-suppressions.json
  • packages/mosaic/src/machine/create-actor.ts
  • packages/mosaic/src/machine/create-machine.ts
  • packages/mosaic/src/machine/setup.ts
  • packages/mosaic/src/machine/types.test-d.ts
  • packages/mosaic/src/machine/types.ts
  • packages/mosaic/src/machine/use-machine.ts
Linked repositories identified

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

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Walkthrough

Machine state-name types now flow from configuration through machine creation, actors, snapshots, and hooks. Transition targets and actor snapshots use the configured state-name type. Type tests cover inferred state-name unions and reject invalid initial states, transition targets, and snapshot values. The changeset file gains empty YAML frontmatter, and the lint suppression count decreases.

Priority: Low

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

Suggested reviewers: ephem

Merge Risk: Minimal · up to b94f9

No confirmed issue prevents merging after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main changes: adding machine state-name typing and validating transition targets in setup machines.
Description check Passed The description directly explains the state-name typing changes, target validation, affected APIs, compatibility behavior, and verification steps.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 6 functions across 6 files. (2 skipped: 2 unsupported.)

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

Warning

Linked repositories: Some configured repositories could not be included in this review. Cross-repository analysis may be incomplete. Please check linked-repository access and settings.

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/electron

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

@clerk/electron-passkeys

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

@clerk/eslint-plugin

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

@clerk/expo

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

@clerk/expo-biometrics

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

@clerk/expo-google-signin

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

@clerk/expo-native-components

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/hono

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

@clerk/localizations

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

@clerk/mosaic

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/react

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

@clerk/react-router

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/ui

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

@clerk/upgrade

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

@clerk/vue

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

commit: b94f92f

This branch was successfully deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant