Skip to content

Commit b24fcae

Browse files
committed
chore: describe skeletons in component skills
1 parent bbd42f6 commit b24fcae

3 files changed

Lines changed: 56 additions & 16 deletions

File tree

‎skills/flat-layers-design/SKILL.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ pages/
237237
index.ts — export * from './Home'; export { Home as default } from './Home'
238238
Home.tsx
239239
Home.module.css
240+
skeleton.tsx — HomePageSkeleton: the page's shape while its code comes
240241
```
241242

242243
- `index.ts` also re-exports the component as `default` so `index.tsx` can lazy-load pages; this is the only place default exports are allowed (lint override for `pages/*/*`).
@@ -246,13 +247,13 @@ pages/
246247
### Entry points
247248

248249
- **CSR:** `index.html` → `app/index.tsx` mounts the app (e.g. `createRoot` in React); the routes → pages tree lives in `app/App.ts`.
249-
- **SSR:** `app/index.tsx` exports `routes` and the `pages` tree (e.g. `layout(RootLayout, [page('home', loadable(() => import('./pages/Home'), AppLoader)), …])`); `app/server.ts` is the HTTP server (Hono); the SSR Vite plugin points at both.
250+
- **SSR:** `app/index.tsx` exports `routes` and the `pages` tree (e.g. `layout(RootLayout, [page('home', loadable(() => import('./pages/Home'), HomePageSkeleton)), …])`); `app/server.ts` is the HTTP server (Hono); the SSR Vite plugin points at both.
250251

251252
## Import conventions
252253

253254
- Cross-layer imports go through the alias: `~/uikit/Button`, `~/stores/garden`, `~/services/garden`.
254255
- Same-layer imports are relative: `../shared/messages`, `../GardenLinks`, `../Text`, `./router`.
255-
- Import through the folder's `index.ts`. Deep imports are reserved for opt-in entry points: `~/uikit/RichTextEditor/loadable`, `~/services/api/api.mock`.
256+
- Import through the folder's `index.ts`. Deep imports are reserved for opt-in entry points: `~/uikit/RichTextEditor/loadable`, `~/uikit/Form/skeleton`, `~/services/api/api.mock`.
256257
- Order inside a file: packages → `~/…` → relative → the CSS module last.
257258

258259
## Stories and tests

‎skills/nanoviews-component/SKILL.md‎

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Use the `ui-component` skill as the base — it holds the framework-agnostic HTM
5959
[ComponentName].stories.ts — stories (optional, if Storybook is used)
6060
[ComponentName].spec.ts — tests (optional, on request)
6161
loadable.ts — lazy-loaded wrapper (optional, when the component pulls in a heavy dependency)
62+
skeleton.ts — the component's skeleton, its shape while it or its data loads (optional)
6263
```
6364

6465
There is no JSX, so every file is `.ts`, never `.tsx`.
@@ -164,31 +165,46 @@ When a component pulls in a heavy dependency (a rich-text editor, a chart librar
164165
// loadable.ts
165166
import { resolved } from 'nanoviews/store'
166167
import {
167-
type Child,
168168
component$,
169169
swap_
170170
} from 'nanoviews'
171171
import type { MDXEditorProps } from './MDXEditor.js'
172+
import { MDXEditorSkeleton } from './skeleton.js'
172173

173-
export interface LoadableMDXEditorProps extends MDXEditorProps {
174-
fallback?: Child
175-
}
176-
177-
export const MDXEditor = component$(({
178-
fallback,
179-
...props
180-
}: LoadableMDXEditorProps, children) => {
174+
export const MDXEditor = component$((props: MDXEditorProps, children) => {
181175
const [$module] = resolved(() => import('./MDXEditor.js'))
182176

183177
return swap_($module, module => (
184178
module
185179
? module.MDXEditor(props)(...children)
186-
: fallback
180+
: MDXEditorSkeleton()
187181
))
188182
})
189183
```
190184

191-
The wrapper keeps the original component name, props and children, adding only an optional `fallback` prop for what stands in while the chunk loads.
185+
The wrapper keeps the original component name, props and children and adds no props. It draws the component's own skeleton from the `skeleton.ts` beside it, the shape of what is coming: no `fallback` prop, and never a `null` branch, which leaves a hole that fills in late.
186+
187+
## Skeletons
188+
189+
A component's shape while it or its data loads is its skeleton, named with the `Skeleton` suffix, never `Loading`: `MDXEditorSkeleton`, `FormSkeleton`. `Loading` names a state, as a `Loading` story or a `LoadingButton` does, not a shape. Every skeleton of a folder lives in the `skeleton.ts` beside the component it draws: a compound's parts (`FormSkeleton`, `FormSectionSkeleton`, `FormGroupSkeleton`), a block's sections, a page's own skeleton and the parts only that page draws.
190+
191+
`skeleton.ts` is an opt-in entry point, as `loadable.ts` is: import it by its path, never re-export it from `index.ts`:
192+
193+
```ts
194+
// not
195+
import {
196+
Form,
197+
FormSkeleton
198+
} from '~/uikit/Form'
199+
200+
// but
201+
import { Form } from '~/uikit/Form'
202+
import { FormSkeleton } from '~/uikit/Form/skeleton'
203+
```
204+
205+
A skeleton stands in while code loads, in a `loadable.ts` or as a route's shape while its page's chunk comes, so it lands in the main chunk. Through `index.ts` it would bring the component it stands in for into that chunk too, with everything the component imports.
206+
207+
A component that is a shape and nothing else, such as the frame every route's skeleton stands in, is an ordinary component named `<Name>Skeleton`, in a folder of its own with the usual files: `skeleton.ts` is for the skeletons of another component.
192208

193209
## Component anatomy
194210

‎skills/react-component/SKILL.md‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Use the `ui-component` skill as the base — it holds the framework-agnostic HTM
5757
[ComponentName].spec.tsx — tests (optional, on request)
5858
use[HookName].ts — component logic extracted into a hook (optional, for complex components with a lot of logic)
5959
loadable.tsx — lazy-loaded wrapper (optional, when the component pulls in a heavy dependency)
60+
skeleton.tsx — the component's skeleton, its shape while it or its data loads (optional)
6061
```
6162

6263
## Reference component
@@ -145,22 +146,44 @@ import {
145146
lazy
146147
} from 'react'
147148
import type { MDXEditorProps } from './MDXEditor'
148-
import { MDXEditorLoading } from './MDXEditorLoading'
149+
import { MDXEditorSkeleton } from './skeleton'
149150

150151
const LazyMDXEditor = lazy(() => import('./MDXEditor').then(({ MDXEditor }) => ({
151152
default: MDXEditor
152153
})))
153154

154155
export function MDXEditor(props: MDXEditorProps) {
155156
return (
156-
<Suspense fallback={<MDXEditorLoading />}>
157+
<Suspense fallback={<MDXEditorSkeleton />}>
157158
<LazyMDXEditor {...props} />
158159
</Suspense>
159160
)
160161
}
161162
```
162163

163-
The wrapper keeps the original component name and props and adds none. It draws its own `<Name>Loading` beside it, the shape of what is coming: no `fallback` prop, and never `fallback={null}`, which leaves a hole that fills in late.
164+
The wrapper keeps the original component name and props and adds none. It draws the component's own skeleton from the `skeleton.tsx` beside it, the shape of what is coming: no `fallback` prop, and never `fallback={null}`, which leaves a hole that fills in late.
165+
166+
## Skeletons
167+
168+
A component's shape while it or its data loads is its skeleton, named with the `Skeleton` suffix, never `Loading`: `MDXEditorSkeleton`, `FormSkeleton`. `Loading` names a state, as a `Loading` story or a `LoadingButton` does, not a shape. Every skeleton of a folder lives in the `skeleton.tsx` beside the component it draws: a compound's parts (`FormSkeleton`, `FormSectionSkeleton`, `FormGroupSkeleton`), a block's sections, a page's own skeleton and the parts only that page draws.
169+
170+
`skeleton.tsx` is an opt-in entry point, as `loadable.tsx` is: import it by its path, never re-export it from `index.ts`:
171+
172+
```tsx
173+
// not
174+
import {
175+
Form,
176+
FormSkeleton
177+
} from '~/uikit/Form'
178+
179+
// but
180+
import { Form } from '~/uikit/Form'
181+
import { FormSkeleton } from '~/uikit/Form/skeleton'
182+
```
183+
184+
A skeleton stands in while code loads, as a `loadable.tsx` fallback or as a route's shape while its page's chunk comes, so it lands in the main chunk. Through `index.ts` it would bring the component it stands in for into that chunk too, with everything the component imports.
185+
186+
A component that is a shape and nothing else, such as the frame every route's skeleton stands in, is an ordinary component named `<Name>Skeleton`, in a folder of its own with the usual files: `skeleton.tsx` is for the skeletons of another component.
164187

165188
## Component anatomy
166189

0 commit comments

Comments
 (0)