Repository navigation
docs(mosaic): give each agent rule one home and trim the guides #10691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1aace54
docs(mosaic): give each agent rule one home and trim the guides
alexcarpenter a02a8cf
docs(mosaic): diet the Mosaic AGENTS.md
alexcarpenter e7d9c85
docs(mosaic): address review feedback on the agent docs
alexcarpenter cb7dcc0
docs(mosaic): narrow the new routing and close rules
alexcarpenter 67d4cbf
docs(mosaic): document models before the API exists and multi-step flows
alexcarpenter f891ab5
docs(mosaic): add onSave to the SsoModel example
alexcarpenter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- |
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Breaking changes | ||
|
|
||
| Read this when a change removes or renames a public export, prop, `--cl-*` token or `.cl-` / `data-` styling hook, or changes a public type or default. It covers the changeset that ships it. | ||
|
|
||
| Worked example: | ||
|
|
||
| ```md | ||
| --- | ||
| '@clerk/mosaic': minor | ||
| --- | ||
|
|
||
| **Breaking:** Rename a `UserButton` prop. Values and defaults are unchanged; TypeScript flags the old name. | ||
|
|
||
| | Before | After | | ||
| | -------------------- | ------------------ | | ||
| | `renderTriggerLabel` | `showTriggerLabel` | | ||
|
|
||
| Find usages with `git grep -n renderTriggerLabel`. | ||
| ``` | ||
|
|
||
| ## Rules | ||
|
|
||
| - While `@clerk/mosaic` is on 0.x, a breaking change is a `minor` changeset. | ||
| - Start the body with `**Breaking:**`, then give an old-to-new table and a search that finds affected usage, so an agent can migrate from the changelog alone. The changelog ships in the npm package at `node_modules/@clerk/mosaic/CHANGELOG.md`. |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Features | ||
|
|
||
| Read this when you add a feature, or a file to one. It covers the model → controller → view split, the files a feature is made of, and how a wrapper composes them; each layer's own rules are in [Models](models.md), [Controllers](controllers.md) and [Views](views.md). | ||
|
|
||
| Worked example: `src/features/reverification/` (model, controller, view, types, messages, wrapper and a feature test). | ||
|
|
||
| ## Rules | ||
|
|
||
| - Before you add a feature, check `packages/ui/src/components/` for a legacy version. If one exists, this is a migration: read [Migration](migration.md) first. | ||
| - Only a `*.model.ts(x)`, or a shared Clerk-reading hook in `src/hooks/` (`useMosaicEnvironment`, `useMosaicRouter`, `useMosaicSupportEmail`), imports Clerk hooks or calls Clerk resource methods. | ||
| - What crosses each boundary is plain data: no Clerk resource reaches the controller, and no machine snapshot reaches the view. | ||
| - A feature's machine lives in its `*.controller.ts(x)`, not in `src/machine/` and not in a `*.machine.ts`. | ||
| - Import from source paths inside `packages/mosaic`; there are no published subpath barrels. | ||
| - A flow is tested as a whole, not per layer ([Testing](testing.md)). | ||
|
|
||
| ## The layers | ||
|
|
||
| Read the split as _where the data comes from_ (model) → _what the user is doing to it_ (controller) → _what that looks like_ (view); the one-paragraph summary is in [AGENTS.md → Layers](../AGENTS.md#layers-in-one-paragraph). A machine is not a layer. It is one of two ways a controller holds its state, chosen by the interaction's complexity ([Controllers → Which one holds the state](controllers.md#which-one-holds-the-state)). | ||
|
|
||
| ## File shape | ||
|
|
||
| A feature lives in `src/features/<feature>/`, one file per role, each prefixed with the feature name. Use `.ts` unless the file renders JSX. | ||
|
|
||
| | File | Holds | | ||
| | ---------------------------- | --------------------------------------------------------------------------- | | ||
| | `<feature>.model.ts(x)` | The Clerk adapter | | ||
| | `<feature>.controller.ts(x)` | Local state, a machine if it has one, and action wrapping | | ||
| | `<feature>.view.tsx` | Rendering only | | ||
| | `<feature>.tsx` | The composition wrapper and the public props type | | ||
| | `<feature>.types.ts` | The data contract the model and view share | | ||
| | `<feature>.messages.ts` | Every string the feature renders ([Views](views.md#where-the-strings-live)) | | ||
| | `<feature>.layout.ts` | Pure derivation, such as which affordance goes in which slot | | ||
| | `<feature>.utils.ts` | Pure helpers | | ||
| | `<feature>.styles.ts` | `stylex.create` atoms ([StyleX](stylex.md)) | | ||
| | `<feature>.skeleton.tsx` | The loading placeholder ([Skeletons](skeletons.md)) | | ||
| | `<name>.dialog.tsx` | A dialog the view opens, when it would crowd the view file | | ||
|
|
||
| `*.types.ts` holds the contract so that neither the model nor the view owns it, and the two cannot drift. | ||
|
|
||
| The other folders under `src/` are named for what they hold; `src/components/` has one folder per component and nothing else. Shared helpers are in the table in [AGENTS.md](../AGENTS.md#reuse-before-you-write), and test helpers are under `src/__tests__/`. | ||
|
|
||
| ## Composition | ||
|
|
||
| Two shapes, chosen by whether the slice fetches its own data. | ||
|
|
||
| - **A wrapper composes the layers** when the slice is a connected component. It calls the model, hands it to the controller, branches on `status`, and renders the view with the rest (`src/features/switcher/switcher.tsx`). `loading` renders the caller's `fallback`; `hidden` renders nothing, because signed out is an answer, not a wait. | ||
| - **A view owns its controller** when the slice is a leaf that takes its effect as a prop. There is no model: the Clerk call arrives from whoever renders it (`UserProfileUsernameRowView` calls `useUserProfileEditUsernameController` with its `onSubmit`). | ||
|
|
||
| Either way, the controller never imports Clerk, and its effects arrive as injected plain functions. |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.