From 3af075d006c471d70628ca907ea89e6f2b7cd672 Mon Sep 17 00:00:00 2001 From: Chris Lorenzo Date: Fri, 20 Nov 2026 13:41:32 -0500 Subject: [PATCH] docs: an AI agent checklist for upgrading an app to 1.8; flex padding rules docs/AI_UPGRADE_1.8.md (new) walks an agent through the 1.7 -> 1.8 changes an app can hit, from MIGRATION-1.8.md: each step gives an rg search, what a match means and what to change, and says to list unclear matches for the developer instead of changing them. The searches were checked against a sample file of matches and near-misses. - package.json: the package ships docs/AI_UPGRADE_1.8.md and MIGRATION-1.8.md next to docs/AI_CODING_GUIDELINES.md, so an agent in an app finds them under node_modules/@solidtv/solid. - docs/_sidebar.md: links both upgrade guides (MIGRATION-1.8.md on GitHub, as the docs site serves docs/ only). - AI_CODING_GUIDELINES.md and essentials/ai_context.md: link the checklist. Padding takes a number, a CSS-style array or per-side props, and margin the same, with one flex engine; both said only a single padding number worked and listed paddingLeft under "do not use". The item flex props add flexShrink, flexBasis, flexOrder and margin. - CLAUDE.md: the same padding rule. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 2 +- docs/AI_CODING_GUIDELINES.md | 13 +- docs/AI_UPGRADE_1.8.md | 265 ++++++++++++++++++++++++++++++++++ docs/_sidebar.md | 2 + docs/essentials/ai_context.md | 13 +- package.json | 4 +- 6 files changed, 285 insertions(+), 14 deletions(-) create mode 100644 docs/AI_UPGRADE_1.8.md diff --git a/CLAUDE.md b/CLAUDE.md index edaa6440..377de09b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -70,5 +70,5 @@ The `@solidtv/source` custom import condition resolves to source `.ts` files ins - Colors must be 8-char hex strings (e.g., `"#ff0000ff"`). No named colors. - Use `color` not `background`. Use object structures for `border`/`shadow`. - No `style={{}}`, no CSS classes, no DOM elements. -- Flex: `display: "flex"` activates it. Only single `padding` number (no `paddingLeft` etc.). Margins, gap, alignItems, justifyContent all supported. +- Flex: `display: "flex"` activates it. `padding` takes a number, a CSS-style array, or per-side `paddingTop`/`paddingRight`/`paddingBottom`/`paddingLeft`. Margins (number, array or per side), gap, alignItems, justifyContent, flexGrow, flexShrink and flexBasis all supported. - Focus: `onFocusChanged`, `onFocus`, `onBlur`, `onEnter`, `onUp`/`onDown`/`onLeft`/`onRight`. One item should have `autofocus`. `Row`/`Column` manage child focus automatically. diff --git a/docs/AI_CODING_GUIDELINES.md b/docs/AI_CODING_GUIDELINES.md index 05a9eae9..93063488 100644 --- a/docs/AI_CODING_GUIDELINES.md +++ b/docs/AI_CODING_GUIDELINES.md @@ -2,6 +2,8 @@ **System Role:** You are an expert frontend engineer working with a custom TV-UI framework called **Lightning**, built on **SolidTV**. +**Upgrading an app from 1.7 to 1.8?** Follow [`docs/AI_UPGRADE_1.8.md`](./AI_UPGRADE_1.8.md), shipped in the package as `node_modules/@solidtv/solid/docs/AI_UPGRADE_1.8.md`. + ## 1. Core Architecture & Runtime - **Environment:** TV app development over WebGL (not the DOM). No pointer input; interaction is directional (Up/Down/Left/Right). @@ -21,8 +23,8 @@ ## 3. Flexbox Engine - **Activation:** Set `display: "flex"` on containers to enable flex layout. -- **Padding:** Supports ONLY a single overall `padding` number. (NO `paddingLeft`, `paddingTop`, etc.). -- **Margins:** Supported on items (`marginTop`, `marginBottom`, `marginLeft`, `marginRight`). +- **Padding:** On the container: a number for all sides, a CSS-style array (`[vertical, horizontal]`, `[top, horizontal, bottom]` or `[top, right, bottom, left]`), or per side with `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft`. A per-side prop overrides that side of `padding`. +- **Margins:** On items: `margin` (a number or the same array forms) and `marginTop`, `marginRight`, `marginBottom`, `marginLeft`. - **Gap:** `gap`, `rowGap`, and `columnGap` are supported. - **Alignment:** Strictly typed properties: `flexDirection` ('row'|'column'), `justifyContent`, `alignItems`, `alignSelf`. @@ -51,11 +53,11 @@ ### Container Flexbox -`display: "flex"`, `flexDirection`, `flexWrap`, `justifyContent`, `alignItems`, `gap`, `rowGap`, `columnGap`, `padding` +`display: "flex"`, `flexDirection`, `flexWrap`, `justifyContent`, `alignItems`, `gap`, `rowGap`, `columnGap`, `padding`, `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft` ### Item Flexbox -`flexGrow`, `flexItem`, `alignSelf`, `marginTop`, `marginBottom`, `marginLeft`, `marginRight` +`flexGrow`, `flexShrink`, `flexBasis`, `flexOrder`, `flexItem`, `alignSelf`, `margin`, `marginTop`, `marginBottom`, `marginLeft`, `marginRight` ### Visual & Text @@ -68,14 +70,13 @@ - The `style={{}}` Prop (Use native node props instead) - `display: 'grid'` - String literal colors without hex (e.g. `'red'`, `'#F00'`) - Use full hex codes like `'#ff0000ff'` -- Directional paddings (e.g., `paddingLeft`) ## 8. Code Examples **❌ Incorrect:** ```tsx -// Missing dimensions, invalid colors, using styles, directional padding +// Missing dimensions, invalid colors, CSS properties in a style prop ` with no size | It no longer blocks its container's layout. | Nothing. | +| `onLayout` on a container that has `flexGrow` children | `onLayout` runs once per layout, with the final layout. It used to run twice. | Remove code that counts calls or skips the first one. | + +## 4. Text in flex containers + +A `` inside a `display="flex"` container, or one with an `onLayout`, is +now measured by Solid right after the change, before the frame. + +1. **Text props written or animated on the renderer node.** Solid is not told + about these, so the container keeps the old size. + + ```sh + rg -n "\.lng\.(text|fontSize|fontFamily|fontStyle|fontWeight|lineHeight|letterSpacing|maxWidth|maxHeight|maxLines|contain|wordWrap|wordBreak|overflowSuffix)\s*=" src + rg -n "\.lng\.animate\(" src + ``` + + Change each match to write or animate on the element instead: + `el.fontSize = 40`, a `transition`, or `el.animate({ fontSize: 40 })`. + Development builds log this warning when it happens, so run the app and + check the console: + + ```text + [solid] A text in a flex container was laid out at a size Solid did not measure + ``` + +2. **Workarounds for layout that arrived late.** Before 1.8, a flex container + with text was laid out after the text's `loaded` event, a frame later. Code + that reads a flex-derived `x`, `y`, `width` or `height` at mount (in an + `onFocus` that fires at mount, an effect, or a `ref` callback) now gets the + laid-out value instead of 0. Look for code that waited for layout before + reading it: + + ```sh + rg -n "onEvent=\{\{[^}]*loaded|loaded:\s*\(" src + rg -n "(setTimeout|requestAnimationFrame|queueMicrotask)\(" src + ``` + + - A `loaded` handler on a text, or on an autosize node, that reads its + parent's layout: it now runs before the parent's relayout. Read the + layout in the parent's `onLayout` instead. + - A `setTimeout` or `requestAnimationFrame` that only waits for flex before + reading positions: it still works. List it for the developer as + removable; do not remove it unasked. + - Code that positions something from a value read at mount, and was tuned + for that value being 0, can now place the element in a different spot. + Check such screens in the running app. + +3. **Text under hidden or culled ancestors** (alpha 0, outside the bounds + margin, kept-alive pages) is now measured eagerly. No code change. A page + with more measured texts than the renderer's `textLayoutCacheSize` (250 by + default) thrashes the cache; if such a page is slow, raise + `textLayoutCacheSize` in `Config.rendererOptions`. + +## 5. States and style objects + +1. **Style objects changed in place.** A `$state` block (`$focus`, `$active`, + …), and a `border` or `shadow` object, is read once and cached by object + identity. Changing it later is not seen. + + ```sh + rg -n "\.\\\$[a-zA-Z]+\.[a-zA-Z]+\s*=" src + rg -n "\.(border|borderTop|borderRight|borderBottom|borderLeft|shadow)\.[a-zA-Z]+\s*=" src + ``` + + For each match that changes an object the app later assigns again (or that + a style already holds), assign a new object instead: + `node.border = { ...node.border, width: 4 }`. A getter in a `$state` block + (`get color() { … }`) is still read every time, so a match inside a getter + is fine. + +2. **Row and Column `transition` changed in place.** After a key press, a + Row's or Column's `transition` is a merged object cached per direction. An + in-place edit of the base `transition` is not seen. + + ```sh + rg -n "\.transition\.[a-zA-Z]+\s*=" src + ``` + + Assign a new `transition` object instead. + +3. **`States` methods on a copy.** `states.slice()`, `filter()`, `map()`, + `splice()` and other `Array` methods now return a plain `Array`, without + `has`, `add` or `toggle`. + + ```sh + rg -n "states\.(slice|filter|map|concat|splice|reduce|flat)\(" src + ``` + + If the result is used as a `States` (`.has(`, `.add(`, `.toggle(`, + `.remove(`), call those methods on `node.states` instead. + +4. **`remove` or `toggle` with a bare name.** `states.remove('focus')` and + `states.toggle('focus')` now act on `'$focus'` when only `'$focus'` is in + the list. Before, they did nothing. + + ```sh + rg -n "states\.(remove|toggle)\(\s*[\"'][a-zA-Z]" src + ``` + + Check each match: if the node can carry the `$`-prefixed state, the call + now changes it. That is usually what the code meant. + +5. **A state change writes only the keys whose value changed.** + - Adding a second state no longer restarts the first state's transition. + - A value the app writes to a key that a state also sets survives a later + state change that leaves that key's value unchanged. Before, the next + state change overwrote it. + - Search for imperative writes to keys a `$state` block sets on the same + node (`color`, `alpha`, `scale`, `border`, `shadow`, …). If the code + relied on a later state change to put the state's value back, write the + value again itself. The border keys (`border`, `borderTop`, …) are still + rewritten together when a state change writes one of them. + +6. **Re-assigning an unchanged `states` list does nothing.** + + ```sh + rg -n "states\s*=\s*[a-zA-Z_.]*states\b" src + ``` + + `node.states = node.states` used to empty the list and re-apply the + styles; it is now a no-op. With `forwardStates`, assigning the parent an + unchanged list no longer resets the children's own states. If the code used + either to re-apply styles, set the states it wants explicitly. + +7. **Shared gradient shaders.** Setting `linearGradient` or `radialGradient` + again now updates the node's shader in place. If the app assigned one + node's `lng.shader` to another node and then set the gradient again, both + nodes change. Give each node its own gradient. + +## 6. Focus callbacks + +The whole focus change (`onFocus`, `onBlur`, `onFocusChanged`, `focusPath`, +`activeElement`) runs in one Solid `batch`. Effects triggered by signals the +callbacks write run once, after the last callback. + +```sh +rg -n "on(Focus|Blur|FocusChanged)=" src +``` + +Look inside each handler for a signal write followed by a read of a node prop +that an effect sets from that signal. That read now sees the old value. Read +the signal itself, or move the read into the effect. Handlers that only write +signals, or only read props, need no change. + +## 7. Draw order + +Overlapping siblings with equal `zIndex` now draw in their `children` order +after every update, as on first render. Before, a node added later (a `` +that appears, a `` item added or moved, a Virtual window shift) was drawn +after all its siblings. + +- An overlay, badge or popup shown with `` or added by ``, that + must draw over later siblings, needs a higher `zIndex`. +- A focused tile with a `$focus` `scale` is now covered by its later siblings, + as on first render. Give the focused state a `zIndex` if it should draw on + top. + +## 8. Removed and ignored writes + +```sh +rg -n "\.(absX|absY|destroyed)\s*=" src +``` + +Writes to `absX`, `absY` and `destroyed` are ignored (they threw on renderer +2.0). Remove them. Text props written to a `` (`fontSize`, `text`, …) +stay on the element and no longer reach `view.lng`; read them from the +element. + +## 9. Build setting + +Find the bundler config (`vite.config.*`, `webpack.config.*`). With terser's +default `reduce_funcs`, renderer 2.0's scene walk allocates on every node it +visits. Set: + +```js +build: { + minify: 'terser', + terserOptions: { compress: { reduce_funcs: false } }, +}, +``` + +Install terser if it is missing (`npm i -D terser`). For webpack: +`new TerserPlugin({ terserOptions: { compress: { reduce_funcs: false } } })`. + +## 10. Verify + +1. Build the app and run its tests. +2. Run it in development mode and check the console for `[solid]` warnings. +3. Open the screens with flex layouts, focus styles and overlays changed or + listed in steps 2 to 7, and compare them with the 1.7 build. +4. Report what you changed, and list every match you left alone with the + reason. diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 0c0a8efa..94b34555 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -4,6 +4,8 @@ - [Migrating from @lightningtv/solid](/migrate.md) - [Migration 2.x to 3.0](/articles/migration-2x-to-3.0.md) - [Upgrading to Renderer 1.9](/articles/renderer-1.9-upgrade.md) + - [Upgrading to 1.8](https://github.com/solid-tv/solid/blob/main/MIGRATION-1.8.md) + - [Upgrading to 1.8 (AI agent checklist)](/AI_UPGRADE_1.8.md) - Core Concepts - [Components](/essentials/components.md) - [ElementNode](/essentials/elementnode.md) diff --git a/docs/essentials/ai_context.md b/docs/essentials/ai_context.md index 298f3290..0e6b9cf2 100644 --- a/docs/essentials/ai_context.md +++ b/docs/essentials/ai_context.md @@ -2,6 +2,8 @@ **System Role:** You are an expert frontend engineer working with a custom TV-UI framework called **Lightning**, built on **SolidTV**. +**Upgrading an app from 1.7 to 1.8?** Follow [`docs/AI_UPGRADE_1.8.md`](/AI_UPGRADE_1.8.md), shipped in the package as `node_modules/@solidtv/solid/docs/AI_UPGRADE_1.8.md`. + ## 1. Core Architecture & Runtime - **Environment:** TV app development over WebGL (not the DOM). No pointer input; interaction is directional (Up/Down/Left/Right). @@ -21,8 +23,8 @@ ## 3. Flexbox Engine - **Activation:** Set `display: "flex"` on containers to enable flex layout. -- **Padding:** Supports ONLY a single overall `padding` number. (NO `paddingLeft`, `paddingTop`, etc.). -- **Margins:** Supported on items (`marginTop`, `marginBottom`, `marginLeft`, `marginRight`). +- **Padding:** On the container: a number for all sides, a CSS-style array (`[vertical, horizontal]`, `[top, horizontal, bottom]` or `[top, right, bottom, left]`), or per side with `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft`. A per-side prop overrides that side of `padding`. +- **Margins:** On items: `margin` (a number or the same array forms) and `marginTop`, `marginRight`, `marginBottom`, `marginLeft`. - **Gap:** `gap`, `rowGap`, and `columnGap` are supported. - **Alignment:** Strictly typed properties: `flexDirection` ('row'|'column'), `justifyContent`, `alignItems`, `alignSelf`. @@ -51,11 +53,11 @@ ### Container Flexbox -`display: "flex"`, `flexDirection`, `flexWrap`, `justifyContent`, `alignItems`, `gap`, `rowGap`, `columnGap`, `padding` +`display: "flex"`, `flexDirection`, `flexWrap`, `justifyContent`, `alignItems`, `gap`, `rowGap`, `columnGap`, `padding`, `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft` ### Item Flexbox -`flexGrow`, `flexItem`, `alignSelf`, `marginTop`, `marginBottom`, `marginLeft`, `marginRight` +`flexGrow`, `flexShrink`, `flexBasis`, `flexOrder`, `flexItem`, `alignSelf`, `margin`, `marginTop`, `marginBottom`, `marginLeft`, `marginRight` ### Visual & Text @@ -68,14 +70,13 @@ - The `style={{}}` Prop (Use native node props instead) - `display: 'grid'` - String literal colors without hex (e.g. `'red'`, `'#F00'`) - Use full hex codes like `'#ff0000ff'` -- Directional paddings (e.g., `paddingLeft`) ## 8. Code Examples **❌ Incorrect:** ```tsx -// Missing dimensions, invalid colors, using styles, directional padding +// Missing dimensions, invalid colors, CSS properties in a style prop