From 62af83b16736ef9b612956307e10fe4ca564d06e Mon Sep 17 00:00:00 2001 From: Chris Lorenzo Date: Fri, 20 Nov 2026 11:03:36 -0500 Subject: [PATCH 1/2] perf(styles): compiled style plans and diffed state application (stream S), B18 as 1.6.4, the final fix wave Ports 1.8's net change across three merges, applied as one 3-way patch so main's #73 border-shader swap is merged once, against the final code: - 0932889 Merge stream S: compiled style plans, diffed state application - 8886583 Merge the final fix wave: no per-call closures on hot paths - de1d782 Merge: remove the B18 fix (Checkpoint 2); border and shadow writes as 1.6.4 Stream S: a $state block, border or shadow object is compiled once and cached by identity (src/core/stylePlan.ts). A state change writes only the keys whose resolved value changed; the border keys are rewritten together in tracked order when one of them changes, as 1.6 did. Assigning an unchanged `states` list does nothing. Setting a gradient again updates the shader it made. B18 stays a known bug (1.6.4 behaviour). Final fix wave, the parts main did not have: the layout phase inline in the post-mutation pass; insertChild, removeChild, animate(), render(), destroy() and _listenTextLoaded without per-call closures or contexts; TextMeasure declares its fields (measureFontWaiting is a static method); flex scratch arrays grown inline; preFlex sizes in the constructor; one shared animation-settings object; onAnimation.stopped without a closure per write; render() reads onEvent with for-in (Chrome 47). Left out, as main already has them: the fix wave's focusManager.ts (8161b66, 7fcd44c; #71) and states.ts (e9a3713, f7b5481; #71) changes and Virtual.tsx (037c0f5; #72). main's tests/states.test.tsx is kept. Merged with main: - #73: the shader accessor and the effects setter keep writing the sub-props into _shaderProps and call _syncShaderType, so a shader convertToShader made still swaps to or from roundedWithBorder when a border width moves to or from 0 (before an animation reads its start values; after it stops for one shrinking to 0). main's convertToShader is kept. - #71's parseAndAssignShaderProps name cache (borderSideMap, shaderPropNames) is replaced by stylePlan's shaderParse. - tests/webgl/shader-props.test.tsx N5 registers roundedWithBorderWithShadow and expects a border written after a shadow to swap to it, per #73; a shadow after a border keeps roundedWithBorder. (cherry picked from commits 0932889c, 8886583, de1d782 on 1.8, net) Co-Authored-By: Claude Opus 5.5 --- docs/essentials/states.md | 8 +- src/core/elementNode.ts | 1007 +++++++++++++++++++---------- src/core/flexLayout.ts | 56 +- src/core/stylePlan.ts | 186 ++++++ src/core/utils.ts | 4 +- tests/contract-states.test.tsx | 72 +++ tests/contract-styles.test.tsx | 32 + tests/layoutQueue.test.tsx | 62 ++ tests/stylePlan.test.ts | 323 +++++++++ tests/webgl/handleFields.test.tsx | 36 +- tests/webgl/shader-props.test.tsx | 804 +++++++++++++++++++++++ 11 files changed, 2234 insertions(+), 356 deletions(-) create mode 100644 src/core/stylePlan.ts create mode 100644 tests/stylePlan.test.ts create mode 100644 tests/webgl/shader-props.test.tsx diff --git a/docs/essentials/states.md b/docs/essentials/states.md index 3a7a5695..a47a2c1d 100644 --- a/docs/essentials/states.md +++ b/docs/essentials/states.md @@ -22,7 +22,7 @@ const Button = { }; ``` -When `Button` is focused via the [useFocusManager](/primitives/useFocusManager.md), the `$focus` state will be added to the button, causing the focus styles to be applied. And when focus is removed, the original styles on the element will be set. +When `Button` is focused via the [useFocusManager](/primitives/useFocusManager.md), the `$focus` state will be added to the button, causing the focus styles to be applied. And when focus is removed, each key the state set goes back to its original value: `theme`'s, else the style object's. > Be sure to set defaults on the original styles if applying a new style via state. Example: clipping: false, focus: { clipping: true } @@ -59,6 +59,12 @@ createEffect(() => { Note: states always use the values in the style object. If you have a button with a base color, and a disabled and focus state which both change the color, the value applied to the button will be determined from the style object. You won't be able to set the color of the button on the JSX `