embedded-react 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/NOTICE +1 -1
  2. package/README.md +1 -1
  3. package/aot/compile.mjs +2 -2
  4. package/aot/compiler/animations.mjs +102 -34
  5. package/aot/compiler/assemble.mjs +27 -5
  6. package/aot/compiler/branch-merge.mjs +5 -9
  7. package/aot/compiler/c/animations.mjs +90 -16
  8. package/aot/compiler/c/nodes.mjs +20 -11
  9. package/aot/compiler/c/statements.mjs +59 -11
  10. package/aot/compiler/check.mjs +32 -3
  11. package/aot/compiler/collect.mjs +46 -2
  12. package/aot/compiler/control-flow.mjs +26 -14
  13. package/aot/compiler/diagnostics.mjs +33 -0
  14. package/aot/compiler/elements/dial.mjs +1 -3
  15. package/aot/compiler/elements/props.mjs +19 -9
  16. package/aot/compiler/elements/text-input.mjs +7 -2
  17. package/aot/compiler/expressions.mjs +29 -7
  18. package/aot/compiler/handlers.mjs +62 -24
  19. package/aot/compiler/keyboard.mjs +35 -21
  20. package/aot/compiler/lower.mjs +3 -3
  21. package/aot/compiler/nodes.mjs +16 -8
  22. package/aot/compiler/options.mjs +63 -12
  23. package/aot/compiler/static-eval.mjs +36 -4
  24. package/aot/compiler/style-text.mjs +35 -12
  25. package/aot/compiler/svg.mjs +7 -3
  26. package/aot/screenshot-smoke.mjs +3 -3
  27. package/aot/style-map.mjs +9 -11
  28. package/assets/bake-svg.mjs +3 -2
  29. package/assets/build-builtin-font.mjs +3 -3
  30. package/assets/emit-c.mjs +6 -4
  31. package/assets/emit-container.mjs +1 -1
  32. package/build.mjs +2 -2
  33. package/compile-bin.mjs +2 -2
  34. package/hotreload/protocol.mjs +1 -1
  35. package/pack-container.mjs +3 -3
  36. package/package.json +7 -7
  37. package/sim/embedded-react.wasm +0 -0
  38. package/src/embedded-react/Animated.js +41 -0
  39. package/src/embedded-react/Button.js +3 -4
  40. package/src/embedded-react/FlatList.js +1 -1
  41. package/src/embedded-react/Pressable.js +59 -0
  42. package/src/embedded-react/TouchableOpacity.js +6 -9
  43. package/src/embedded-react/index.d.ts +118 -30
  44. package/src/embedded-react/index.js +1 -1
  45. package/src/embedded-react/named-colors.js +37 -0
  46. package/src/embedded-react/svg-ops.js +13 -16
  47. package/src/host-config.js +50 -8
@@ -27,7 +27,7 @@
27
27
  // Flow B (the AOT compiler) lowers a documented SUBSET of this surface and fails the build on anything it
28
28
  // cannot compile, so these types describe Flow A and the AOT reports the difference.
29
29
 
30
- import type {ReactNode, Ref} from 'react';
30
+ import type {ComponentType, ReactNode, Ref} from 'react';
31
31
 
32
32
  /** A node handle: what a `ref` on a host component receives, and what the imperative API takes. */
33
33
  export type NodeHandle = number;
@@ -35,8 +35,8 @@ export type NodeHandle = number;
35
35
  // --- Styling ---------------------------------------------------------------
36
36
 
37
37
  /**
38
- * A box dimension. Percentage strings are resolved for `width` and `height` only — every other box
39
- * property (margins, padding, min/max, borders, insets) takes pixels and ignores a string.
38
+ * A box dimension. Percentage strings are resolved for `width`, `height`, `flexBasis` and the insets —
39
+ * every other box property (margins, padding, min/max, borders) takes pixels and ignores a string.
40
40
  */
41
41
  export type DimensionValue = number | `${number}%`;
42
42
 
@@ -50,19 +50,19 @@ export interface ShadowOffset {
50
50
  export type TransformOrigin = [number, number];
51
51
 
52
52
  /**
53
- * One transform entry. Every axis except `perspective` can be driven by an `AnimatedValue`; `scale` binds
53
+ * One transform entry. Every axis except `perspective` can be driven by an animated value; `scale` binds
54
54
  * both axes at once. Rotations are CSS angle strings ('45deg', '0.5rad').
55
55
  */
56
56
  export type TransformStyle =
57
- | {scale: number | AnimatedValue}
58
- | {scaleX: number | AnimatedValue}
59
- | {scaleY: number | AnimatedValue}
60
- | {translateX: number | AnimatedValue}
61
- | {translateY: number | AnimatedValue}
62
- | {rotate: string | AnimatedValue}
63
- | {rotateX: string | AnimatedValue}
64
- | {rotateY: string | AnimatedValue}
65
- | {rotateZ: string | AnimatedValue}
57
+ | {scale: number | AnimatedNode}
58
+ | {scaleX: number | AnimatedNode}
59
+ | {scaleY: number | AnimatedNode}
60
+ | {translateX: number | AnimatedNode}
61
+ | {translateY: number | AnimatedNode}
62
+ | {rotate: string | AnimatedNode}
63
+ | {rotateX: string | AnimatedNode}
64
+ | {rotateY: string | AnimatedNode}
65
+ | {rotateZ: string | AnimatedNode}
66
66
  | {perspective: number};
67
67
 
68
68
  /**
@@ -73,7 +73,7 @@ export type TransformStyle =
73
73
  export type StyleValue =
74
74
  | string
75
75
  | number
76
- | AnimatedValue
76
+ | AnimatedNode
77
77
  | TransformStyle[]
78
78
  | ShadowOffset
79
79
  | TransformOrigin
@@ -121,7 +121,7 @@ export interface ViewStyle {
121
121
  flex?: number;
122
122
  flexGrow?: number;
123
123
  flexShrink?: number;
124
- flexBasis?: number;
124
+ flexBasis?: DimensionValue;
125
125
  flexDirection?: 'row' | 'column' | 'row-reverse' | 'column-reverse';
126
126
  flexWrap?: 'nowrap' | 'wrap' | 'wrap-reverse';
127
127
  justifyContent?:
@@ -157,8 +157,8 @@ export interface ViewStyle {
157
157
  pointerEvents?: 'auto' | 'none' | 'box-none' | 'box-only';
158
158
 
159
159
  // Paint.
160
- backgroundColor?: string | AnimatedValue;
161
- opacity?: number | AnimatedValue;
160
+ backgroundColor?: string | AnimatedNode;
161
+ opacity?: number | AnimatedNode;
162
162
 
163
163
  // Border.
164
164
  borderRadius?: number;
@@ -191,7 +191,7 @@ export interface ViewStyle {
191
191
  }
192
192
 
193
193
  export interface TextStyle extends ViewStyle {
194
- color?: string | AnimatedValue;
194
+ color?: string | AnimatedNode;
195
195
  fontSize?: number;
196
196
  fontFamily?: string;
197
197
  /** Anything from 600 up (or 'bold') selects the bold face; the engine carries no other weights. */
@@ -218,7 +218,7 @@ export type StyleProp<T> = T | false | null | undefined | StyleProp<T>[];
218
218
 
219
219
  // --- Events ----------------------------------------------------------------
220
220
 
221
- /** The laid-out box reported by `onLayout`, in screen coordinates (not parent-relative). */
221
+ /** The laid-out box reported by `onLayout`. `x`/`y` are relative to the parent, as in React Native. */
222
222
  export interface LayoutRectangle {
223
223
  x: number;
224
224
  y: number;
@@ -289,6 +289,8 @@ export interface ScrollEvent extends NativeEvent<'scroll'> {
289
289
 
290
290
  export interface LayoutChangeEvent extends NativeEvent<'layout'> {
291
291
  layout: LayoutRectangle;
292
+ /** The same rect, where React Native puts it. */
293
+ nativeEvent: {layout: LayoutRectangle};
292
294
  }
293
295
 
294
296
  /**
@@ -558,7 +560,7 @@ export interface DialGradient {
558
560
  export interface DialProps extends TouchEventProps {
559
561
  style?: StyleProp<ViewStyle>;
560
562
  /** Current value in [min, max]. Animatable with Animated.Value (native driver). */
561
- value?: number | AnimatedValue;
563
+ value?: number | AnimatedNode;
562
564
  min?: number;
563
565
  max?: number;
564
566
  startAngle?: number;
@@ -593,7 +595,7 @@ export interface DialProps extends TouchEventProps {
593
595
  */
594
596
  range?: boolean;
595
597
  /** RANGE mode: the band's low end. Animatable like `value`. */
596
- valueStart?: number | AnimatedValue;
598
+ valueStart?: number | AnimatedNode;
597
599
  /**
598
600
  * RANGE mode: the minimum separation the two ends keep, in value units. 0 (default) lets them meet.
599
601
  * Above 0, a drag that would close the gap pushes the far end along instead of stopping dead, and
@@ -772,6 +774,12 @@ export const Arc: (props: ArcProps) => JSX.Element;
772
774
  // --- StyleSheet ------------------------------------------------------------
773
775
  export const StyleSheet: {
774
776
  create<T extends Record<string, ViewStyle | TextStyle>>(styles: T): T;
777
+ /** Merges a style array (nested, with falsy entries skipped) into one object; later entries win. */
778
+ flatten(style?: StyleProp<ViewStyle>): ViewStyle;
779
+ /** 1 — the engine draws whole pixels, so the thinnest line is one. */
780
+ hairlineWidth: number;
781
+ /** `{position: 'absolute', top: 0, left: 0, right: 0, bottom: 0}`. */
782
+ absoluteFill: ViewStyle;
775
783
  };
776
784
 
777
785
  // --- Platform --------------------------------------------------------------
@@ -789,21 +797,95 @@ export const AppRegistry: {
789
797
  };
790
798
 
791
799
  // --- Animated --------------------------------------------------------------
800
+ /** Behavior outside `inputRange`: keep the slope ('extend'), hold the end value, or pass the input through. */
801
+ export type ExtrapolateType = 'extend' | 'clamp' | 'identity';
802
+
803
+ /**
804
+ * A piecewise-linear mapping, up to 8 breakpoints. `outputRange` is numbers, or colors for
805
+ * `backgroundColor` and `color`, which take nothing else; the engine carries no unit-string
806
+ * interpolation, and a rotation axis reads the output in degrees. `extrapolate` sets both ends and the
807
+ * per-end keys override it.
808
+ */
809
+ export interface InterpolationConfig {
810
+ inputRange: number[];
811
+ outputRange: number[] | string[];
812
+ extrapolate?: ExtrapolateType;
813
+ extrapolateLeft?: ExtrapolateType;
814
+ extrapolateRight?: ExtrapolateType;
815
+ }
816
+
817
+ /** Anything a style or `Dial` value can be bound to: an `AnimatedValue` or one of its interpolations. */
818
+ export interface AnimatedNode {
819
+ interpolate(config: InterpolationConfig): AnimatedNode;
820
+ }
821
+
792
822
  // A handle to an engine-side animated float. Not importable directly — obtain one from `useAnimatedValue`
793
823
  // or `new Animated.Value(...)`, so this is a type, not a runtime export.
794
- export interface AnimatedValue {
824
+ export interface AnimatedValue extends AnimatedNode {
795
825
  setValue(value: number): void;
796
- interpolate(config: {
797
- inputRange: number[];
798
- outputRange: number[] | string[];
799
- }): AnimatedValue;
826
+ /**
827
+ * Frees the engine-side slot. The value pool is fixed-size, so a `new Animated.Value` that outlives its
828
+ * screen must be destroyed; `useAnimatedValue` does it on unmount. Idempotent.
829
+ */
830
+ destroy(): void;
831
+ }
832
+
833
+ /** A named engine curve. */
834
+ export type EasingName =
835
+ | 'linear'
836
+ | 'ease'
837
+ | 'easeIn'
838
+ | 'easeOut'
839
+ | 'easeInOut'
840
+ | 'quadIn'
841
+ | 'quadOut'
842
+ | 'quadInOut'
843
+ | 'cubicIn'
844
+ | 'cubicOut'
845
+ | 'cubicInOut'
846
+ | 'bounceOut'
847
+ | 'elasticOut';
848
+
849
+ /** A custom cubic-bezier curve, from `Easing.bezier`. */
850
+ export interface BezierEasing {
851
+ x1: number;
852
+ y1: number;
853
+ x2: number;
854
+ y2: number;
800
855
  }
801
856
 
857
+ /** An `Easing` token. The engine evaluates the curve; it is not a JS function. */
858
+ export type EasingCurve = EasingName | BezierEasing;
859
+
860
+ /** `Animated.timing` config. */
802
861
  export interface AnimationConfig {
803
862
  toValue: number;
804
863
  duration?: number;
805
864
  delay?: number;
806
- easing?: (t: number) => number;
865
+ easing?: EasingCurve;
866
+ useNativeDriver?: boolean;
867
+ }
868
+
869
+ /** `Animated.spring` config, in the engine's physical parameters (RN's `tension`/`friction` are not read). */
870
+ export interface SpringAnimationConfig {
871
+ toValue: number;
872
+ /** Default 100. */
873
+ stiffness?: number;
874
+ /** Default 10. */
875
+ damping?: number;
876
+ /** Default 1. */
877
+ mass?: number;
878
+ velocity?: number;
879
+ delay?: number;
880
+ useNativeDriver?: boolean;
881
+ }
882
+
883
+ /** `Animated.decay` config. There is no target: the value coasts from `velocity`. */
884
+ export interface DecayAnimationConfig {
885
+ /** Value units per ms. */
886
+ velocity: number;
887
+ /** Per-ms friction. Default 0.998. */
888
+ deceleration?: number;
807
889
  useNativeDriver?: boolean;
808
890
  }
809
891
 
@@ -818,8 +900,8 @@ export const Animated: {
818
900
  Text: (props: TextProps) => JSX.Element;
819
901
  Image: (props: ImageProps) => JSX.Element;
820
902
  timing(value: AnimatedValue, config: AnimationConfig): Animation;
821
- spring(value: AnimatedValue, config: AnimationConfig): Animation;
822
- decay(value: AnimatedValue, config: Record<string, unknown>): Animation;
903
+ spring(value: AnimatedValue, config: SpringAnimationConfig): Animation;
904
+ decay(value: AnimatedValue, config: DecayAnimationConfig): Animation;
823
905
  sequence(animations: Animation[]): Animation;
824
906
  parallel(
825
907
  animations: Animation[],
@@ -831,6 +913,10 @@ export const Animated: {
831
913
  config?: {iterations?: number; resetBeforeIteration?: boolean},
832
914
  ): Animation;
833
915
  delay(ms: number): Animation;
916
+ /** RN parity: a pass-through wrapper, since any component binds an animated style already. */
917
+ createAnimatedComponent<P>(
918
+ component: ComponentType<P>,
919
+ ): (props: P) => JSX.Element;
834
920
  };
835
921
 
836
922
  /** Creates an AnimatedValue tied to the component lifecycle (destroyed on unmount). */
@@ -843,7 +929,9 @@ export function usePersistentState<S>(
843
929
  ): [S, (value: S | ((prev: S) => S)) => void];
844
930
 
845
931
  export function useHostValue(initial: number): number;
846
- export const Easing: Record<string, (t: number) => number>;
932
+ export const Easing: {readonly [K in EasingName]: K} & {
933
+ bezier(x1: number, y1: number, x2: number, y2: number): BezierEasing;
934
+ };
847
935
  export const LayoutAnimation: Record<string, unknown>;
848
936
 
849
937
  // --- PanResponder ----------------------------------------------------------
@@ -26,7 +26,6 @@ export {
26
26
  Text,
27
27
  Image,
28
28
  ScrollView,
29
- Pressable,
30
29
  TextInput,
31
30
  Switch,
32
31
  ActivityIndicator,
@@ -41,6 +40,7 @@ export {
41
40
  G,
42
41
  Arc,
43
42
  } from './components.js';
43
+ export {Pressable} from './Pressable.js';
44
44
  export {Button} from './Button.js';
45
45
  export {TouchableOpacity} from './TouchableOpacity.js';
46
46
  export {FlatList} from './FlatList.js';
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ // The named colors every path accepts, as ARGB8888 with their CSS values. Keys are lowercase; callers
18
+ // lowercase the name first. The bridge's k_named table (native_ui_bridge.c) must list the same entries.
19
+ // No prototype, so `name in NAMED_COLORS` never finds `toString` and friends.
20
+
21
+ /** @type {Readonly<Record<string, number>>} */
22
+ export const NAMED_COLORS = Object.freeze(
23
+ Object.assign(Object.create(null), {
24
+ transparent: 0x00000000,
25
+ black: 0xff000000,
26
+ white: 0xffffffff,
27
+ red: 0xffff0000,
28
+ green: 0xff008000,
29
+ blue: 0xff0000ff,
30
+ gray: 0xff808080,
31
+ grey: 0xff808080,
32
+ yellow: 0xffffff00,
33
+ cyan: 0xff00ffff,
34
+ magenta: 0xffff00ff,
35
+ orange: 0xffffa500,
36
+ }),
37
+ );
@@ -22,6 +22,8 @@
22
22
  // shapes to path ops, bakes viewBox + <G> translate/scale into coordinates, and resolves inherited
23
23
  // paint. The opcodes below MUST stay in sync with er_scene.h.
24
24
 
25
+ import {NAMED_COLORS} from './named-colors.js';
26
+
25
27
  // Op-tape vocabulary — exported so the build-time SVG baker (assets/bake-svg.mjs) can reuse it without
26
28
  // duplicating the encoding (and without pulling its SVG-parser dependency into this runtime module).
27
29
  export const VOP_SHAPE = 0;
@@ -115,18 +117,10 @@ export function encodeVectorGradients(grads) {
115
117
  return out;
116
118
  }
117
119
 
118
- // Minimal named-color set (extend as needed); everything else goes through hex/rgb parsing.
119
- const NAMED = {
120
- none: 0,
121
- transparent: 0,
122
- black: 0xff000000,
123
- white: 0xffffffff,
124
- red: 0xffff0000,
125
- green: 0xff008000,
126
- blue: 0xff0000ff,
127
- gray: 0xff808080,
128
- grey: 0xff808080,
129
- };
120
+ // The shared named colors plus SVG's `none`; everything else goes through hex/rgb parsing.
121
+ const NAMED = Object.freeze(
122
+ Object.assign(Object.create(null), NAMED_COLORS, {none: 0}),
123
+ );
130
124
 
131
125
  // Cache string->uint32 results: a theme reuses a handful of color strings, so on a continuous drag
132
126
  // (which recompiles the dial every move) this turns repeated hex parsing into a Map lookup.
@@ -135,7 +129,7 @@ const _colorCache = new Map();
135
129
  /**
136
130
  * Parses a CSS color string to a uint32 ARGB8888. Returns 0 (fully transparent) for none/transparent/
137
131
  * null, so the engine treats it as "no fill"/"no stroke". Accepts #rgb, #rgba, #rrggbb, #rrggbbaa,
138
- * rgb()/rgba(), and the small named set above. String results are memoised (see _colorCache).
132
+ * rgb()/rgba(), and the named colors above. String results are memoised (see _colorCache).
139
133
  */
140
134
  export function parseColor(c) {
141
135
  if (c == null || c === false) return 0;
@@ -785,10 +779,12 @@ const PAINT_DEFAULT = {
785
779
  strokeGrad: null,
786
780
  };
787
781
 
782
+ /** The props that make up a shape's paint; a <G> or the <Svg> itself passes them down. */
783
+ export const PAINT_PROPS = Object.keys(PAINT_DEFAULT);
784
+
788
785
  function mergePaint(base, props) {
789
786
  const out = {...base};
790
- for (const k of Object.keys(PAINT_DEFAULT))
791
- if (props[k] != null) out[k] = props[k];
787
+ for (const k of PAINT_PROPS) if (props[k] != null) out[k] = props[k];
792
788
  return out;
793
789
  }
794
790
 
@@ -1006,7 +1002,8 @@ export function flattenSvg(props) {
1006
1002
  for (let k = 0; k < seg.length; k++) ops.push(seg[k]);
1007
1003
  };
1008
1004
 
1009
- walk(props.children, PAINT_DEFAULT, root);
1005
+ // The <Svg>'s own paint cascades to every shape, like a <G> wrapping them all.
1006
+ walk(props.children, mergePaint(PAINT_DEFAULT, props), root);
1010
1007
  return {ops, paints, gradients};
1011
1008
  }
1012
1009
 
@@ -14,10 +14,6 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- // react-reconciler host config: translates React's mutation API into NativeUI.* calls.
18
- //
19
- // Instances ARE the integer node handles returned by NativeUI.createNode(). We keep no JS-side
20
- // wrapper objects — the engine owns the scene graph, the handle is the identity.
21
17
  import {DefaultEventPriority} from 'react-reconciler/constants';
22
18
  import {NativeUI} from './native-ui.js';
23
19
  import {
@@ -29,6 +25,7 @@ import {
29
25
  } from './props.js';
30
26
  import {
31
27
  flattenSvg,
28
+ PAINT_PROPS,
32
29
  warnVectorCaps,
33
30
  scaleVectorArtifact,
34
31
  encodeVectorGradients,
@@ -113,6 +110,36 @@ function forgetBindings(handle) {
113
110
  boundValues.delete(handle);
114
111
  }
115
112
 
113
+ // --- Failed creates ------------------------------------------------------------------------------
114
+ // createNode returns 0 when the node pool is full. React creates children before their parent, so the
115
+ // children of a parent that did not fit are never attached to anything, and removing that parent frees
116
+ // nothing in C. Each failed create gets its own negative instance (the bridge ignores handles <= 0), and
117
+ // the children appended to it are kept here so they are freed when it is deleted.
118
+ const orphansOf = new Map(); // failed instance → Set of child handles
119
+ let nextFailedInstance = -1;
120
+
121
+ /** Records `child` as held by `parent` when `parent` is a failed create. */
122
+ function adoptIfOrphan(parent, child) {
123
+ if (parent >= 0 || child <= 0) return;
124
+ let orphans = orphansOf.get(parent);
125
+ if (orphans === undefined) {
126
+ orphans = new Set();
127
+ orphansOf.set(parent, orphans);
128
+ }
129
+ orphans.add(child);
130
+ }
131
+
132
+ /** Frees the children a failed create was holding. */
133
+ function freeOrphans(instance) {
134
+ const orphans = orphansOf.get(instance);
135
+ if (orphans === undefined) return;
136
+ orphansOf.delete(instance);
137
+ for (const child of orphans) {
138
+ NativeUI.destroyNode(child);
139
+ forgetBindings(child);
140
+ }
141
+ }
142
+
116
143
  /**
117
144
  * Applies a node's resolved props, binding any Animated.Value found in its `style` to the matching
118
145
  * node prop (native driver). This makes animated styles work on ANY host element — `<Pressable
@@ -260,8 +287,9 @@ function svgSourceBoxChanged(prevProps, nextProps) {
260
287
  *
261
288
  * The vector flag tracks the op-tape's actual inputs. A source artifact tape depends on the source
262
289
  * reference and the resolved box; a declarative <Svg><Path/></Svg> tape depends on the shape
263
- * children, viewBox, and the direct width/height props (flattenSvg never reads style). So a
264
- * position-only style move of either kind — the interactive-drag hot path — skips the upload.
290
+ * children, viewBox, the direct width/height props, and its own paint props, which cascade to its
291
+ * shapes (flattenSvg never reads style). So a position-only style move of either kind — the
292
+ * interactive-drag hot path — skips the upload.
265
293
  *
266
294
  * Props buildProps never reads still set the props flag when they change — conservative, and only
267
295
  * paid when such a value actually changed.
@@ -314,7 +342,12 @@ function diffUpdate(type, prevProps, nextProps) {
314
342
  }
315
343
  // fall through: on other types these are ordinary (ignored or passthrough) props
316
344
  default:
317
- if (!deepEqualProps(a, b)) props = true;
345
+ if (!deepEqualProps(a, b)) {
346
+ props = true;
347
+ // A source tape ignores root paint.
348
+ if (type === 'Svg' && !nextProps.source && PAINT_PROPS.includes(key))
349
+ vector = true;
350
+ }
318
351
  }
319
352
  };
320
353
  for (const key in prevProps) diffKey(key);
@@ -385,12 +418,14 @@ export const hostConfig = {
385
418
  const raster = rasterSvgArtifact(type, props);
386
419
  if (raster) {
387
420
  const handle = NativeUI.createNode('Image');
421
+ if (handle === 0) return nextFailedInstance--;
388
422
  forgetBindings(handle);
389
423
  applyProps('Image', handle, rasterImageProps(props, raster));
390
424
  applyEvents(handle, null, props);
391
425
  return handle;
392
426
  }
393
427
  const handle = NativeUI.createNode(type);
428
+ if (handle === 0) return nextFailedInstance--;
394
429
  forgetBindings(handle);
395
430
  const flatStyle = applyProps(type, handle, props);
396
431
  applyTextSpans(type, handle, props, flatStyle);
@@ -407,6 +442,7 @@ export const hostConfig = {
407
442
  },
408
443
  appendInitialChild(parent, child) {
409
444
  NativeUI.appendChild(parent, child);
445
+ adoptIfOrphan(parent, child);
410
446
  },
411
447
  finalizeInitialChildren() {
412
448
  return false;
@@ -423,18 +459,21 @@ export const hostConfig = {
423
459
  // --- Mutation ---
424
460
  appendChild(parent, child) {
425
461
  NativeUI.appendChild(parent, child);
462
+ adoptIfOrphan(parent, child);
426
463
  },
427
464
  appendChildToContainer(container, child) {
428
465
  NativeUI.appendChild(container, child);
429
466
  },
430
467
  insertBefore(parent, child, beforeChild) {
431
468
  NativeUI.insertBefore(parent, child, beforeChild);
469
+ adoptIfOrphan(parent, child);
432
470
  },
433
471
  insertInContainerBefore(container, child, beforeChild) {
434
472
  NativeUI.insertBefore(container, child, beforeChild);
435
473
  },
436
474
  removeChild(parent, child) {
437
475
  NativeUI.removeChild(parent, child);
476
+ orphansOf.get(parent)?.delete(child);
438
477
  NativeUI.destroyNode(child);
439
478
  forgetBindings(child);
440
479
  },
@@ -473,7 +512,10 @@ export const hostConfig = {
473
512
  },
474
513
 
475
514
  // --- Misc required hooks (no-ops for our renderer) ---
476
- detachDeletedInstance() {},
515
+ detachDeletedInstance(instance) {
516
+ // Called for every host instance in a deleted subtree, including failed creates below its top.
517
+ if (instance < 0) freeOrphans(instance);
518
+ },
477
519
  getCurrentEventPriority() {
478
520
  return DefaultEventPriority;
479
521
  },