@symbiote-native/engine 0.3.0 → 0.4.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.
package/build/debug.js CHANGED
@@ -12,11 +12,17 @@
12
12
  // logging off. On a hot path (a getter Angular re-reads every change-detection
13
13
  // pass, an Animated reconcile, a scroll-driven apply) pass a THUNK instead:
14
14
  // `dlog(() => \`…\`)` - it is only called once the switch is on.
15
- function envEnabled() {
16
- return typeof process !== 'undefined' && process.env.DEBUG === '1';
17
- }
15
+ // Read ONCE, at module load. `process.env` is not a plain object in Node - each property read
16
+ // crosses into the host environment - and isDebug() is called on the per-node commit path, so the
17
+ // per-call read showed up as 17% of self time in a create-path CPU profile (headless; on a native
18
+ // host `process` is a shim and the read is cheap, so treat that figure as a Node one).
19
+ //
20
+ // Safe to freeze because nothing toggles the ENV switch mid-process: every runtime toggle in the
21
+ // repo goes through __SYMBIOTE_DEBUG__ below, which stays dynamic, and bootstrap mirrors the env
22
+ // onto it at start anyway.
23
+ const envDebug = typeof process !== 'undefined' && process.env.DEBUG === '1';
18
24
  export function isDebug() {
19
- return globalThis.__SYMBIOTE_DEBUG__ === true || envEnabled();
25
+ return envDebug || globalThis.__SYMBIOTE_DEBUG__ === true;
20
26
  }
21
27
  export function dlog(message) {
22
28
  if (!isDebug())
@@ -92,32 +92,34 @@ const DEFAULT_LONG_PRESS_MS = 500;
92
92
  // points from where it started (Pressability.DEFAULT_LONG_PRESS_DEACTIVATION_DISTANCE).
93
93
  const LONG_PRESS_DEACTIVATION_DISTANCE = 10;
94
94
  let installed = false;
95
- // Target of the in-flight touch, remembered at topTouchStart and consumed (or
96
- // cleared) at topTouchEnd / topTouchCancel.
97
- let pressStart;
95
+ // Each unrelated target owns an independent press. Additional fingers under the same owner join
96
+ // that press, so one target still receives exactly one pressIn/press/pressOut lifecycle.
97
+ const activePresses = new Set();
98
98
  // The node that claimed the responder for the in-flight touch (PanResponder), or
99
99
  // undefined when nobody claimed it. Receives move and release/terminate.
100
100
  let currentResponder;
101
- // Long-press synthesis: armed at touch start when some node in the press path listens
102
- // for it, fired once after the hold delay, disarmed on end/cancel; the same arm/clear
103
- // lifecycle Pressable runs in JS. Pressability ALSO cancels the timer when the touch
104
- // drifts past LONG_PRESS_DEACTIVATION_DISTANCE, so we record the start point at touch
105
- // start and clear the timer on a move that exceeds it.
106
- let longPressTimer;
107
- let longPressFired = false;
108
- // Touch coordinate at touch start (pageX/pageY), or undefined when the native event
109
- // carried no coords; then the move-distance cancel is simply skipped.
110
- let longPressStart;
111
- function clearLongPress() {
112
- if (longPressTimer !== undefined) {
113
- clearTimeout(longPressTimer);
114
- longPressTimer = undefined;
101
+ function clearLongPress(press) {
102
+ if (press.longPressTimer !== undefined) {
103
+ clearTimeout(press.longPressTimer);
104
+ press.longPressTimer = undefined;
115
105
  }
116
106
  }
117
- // Read the gesture's page coordinate from a raw native touch event, defensively: RN
118
- // puts pageX/pageY on the event for a single touch, or on the first entry of a
119
- // `touches` array for multi-touch. Returns undefined when neither shape carries
120
- // numbers, so callers skip any coordinate-dependent logic rather than guess.
107
+ function takeAllPresses() {
108
+ const presses = [...activePresses];
109
+ activePresses.clear();
110
+ for (const press of presses)
111
+ clearLongPress(press);
112
+ return presses;
113
+ }
114
+ function findActivePress(target) {
115
+ for (const press of activePresses) {
116
+ if (endsWithin(target, press.owner))
117
+ return press;
118
+ }
119
+ return undefined;
120
+ }
121
+ // Read the changed finger's page coordinate from a raw native touch event, falling back to the
122
+ // active-touch list and then undefined. Callers skip coordinate-dependent logic rather than guess.
121
123
  function readTouchPoint(nativeEvent) {
122
124
  const fromPair = (source) => {
123
125
  if (!source)
@@ -130,21 +132,27 @@ function readTouchPoint(nativeEvent) {
130
132
  const direct = fromPair(nativeEvent);
131
133
  if (direct)
132
134
  return direct;
133
- const touches = nativeEvent.touches;
134
- if (Array.isArray(touches)) {
135
- const first = touches[0];
136
- if (isRecord(first))
137
- return fromPair(first);
135
+ // `changedTouches` identifies the finger for this frame. Read it before the full active-touch
136
+ // list, whose first entry may belong to another simultaneously pressed target.
137
+ for (const key of ['changedTouches', 'touches']) {
138
+ const touches = nativeEvent[key];
139
+ if (!Array.isArray(touches))
140
+ continue;
141
+ for (const touch of touches) {
142
+ if (!isRecord(touch))
143
+ continue;
144
+ const point = fromPair(touch);
145
+ if (point)
146
+ return point;
147
+ }
138
148
  }
139
149
  return undefined;
140
150
  }
141
- // Whether any touch still down started inside the responder (its target IS the
142
- // responder or a descendant). RN's noResponderTouches walks nativeEvent.touches and
143
- // returns false the moment one is found; a release fires only when none remain. The
144
- // headless smokes fire with an empty `{}` event (no `touches`) -> no remaining touch ->
145
- // release fires, preserving single-touch behavior. (ResponderEventPlugin.noResponder-
146
- // Touches + isAncestor.)
147
- function hasRemainingResponderTouch(responder, nativeEvent) {
151
+ // Whether any touch still down started inside an owner (its target IS the owner or a descendant).
152
+ // RN's noResponderTouches walks nativeEvent.touches and returns false the moment one is found; a
153
+ // responder release and our synthesized press completion both wait until none remain. The headless
154
+ // smokes fire with an empty `{}` event -> no remaining touch -> preserve single-touch behavior.
155
+ function hasRemainingTouchWithin(owner, nativeEvent) {
148
156
  const touches = nativeEvent.touches;
149
157
  if (!Array.isArray(touches))
150
158
  return false;
@@ -152,7 +160,7 @@ function hasRemainingResponderTouch(responder, nativeEvent) {
152
160
  if (!isRecord(touch))
153
161
  continue;
154
162
  const target = touch.target;
155
- if (isSymbioteNode(target) && endsWithin(target, responder))
163
+ if (isSymbioteNode(target) && endsWithin(target, owner))
156
164
  return true;
157
165
  }
158
166
  return false;
@@ -306,23 +314,41 @@ export function installEventHandler() {
306
314
  // read each touch's own previous->current delta; RN records before dispatch.
307
315
  recordTouchTrack('start', nativeEvent);
308
316
  attachTouchHistory(nativeEvent);
309
- pressStart = instanceHandle;
310
- // Arm long-press synthesis: only when a listener exists in the path, fired once
311
- // after the hold delay, then suppresses the tap (longPressFired) on release.
312
- longPressFired = false;
313
- clearLongPress();
314
- longPressStart = readTouchPoint(nativeEvent);
315
- if (hasListenerInPath(instanceHandle, LONG_PRESS)) {
316
- const longPressTarget = instanceHandle;
317
- longPressTimer = setTimeout(() => {
318
- longPressTimer = undefined;
319
- longPressFired = true;
320
- dlog('synthesized longPress -> dispatch');
321
- runWrapped(() => bubble(longPressTarget, LONG_PRESS, nativeEvent));
322
- }, DEFAULT_LONG_PRESS_MS);
317
+ const canJoinExistingPress = Array.isArray(nativeEvent.touches) && nativeEvent.touches.length > 1;
318
+ const joinedPress = canJoinExistingPress
319
+ ? findActivePress(instanceHandle)
320
+ : undefined;
321
+ // A one-touch or identifier-less frame starts a new physical gesture. Any surviving press
322
+ // is stale (its end/cancel was lost), so release it instead of letting it suppress this start.
323
+ const stalePresses = canJoinExistingPress ? [] : takeAllPresses();
324
+ let startedPress;
325
+ if (joinedPress === undefined) {
326
+ startedPress = {
327
+ owner: instanceHandle,
328
+ longPressTimer: undefined,
329
+ longPressFired: false,
330
+ longPressStart: readTouchPoint(nativeEvent),
331
+ };
332
+ activePresses.add(startedPress);
333
+ if (hasListenerInPath(instanceHandle, LONG_PRESS)) {
334
+ const press = startedPress;
335
+ press.longPressTimer = setTimeout(() => {
336
+ if (!activePresses.has(press))
337
+ return;
338
+ press.longPressTimer = undefined;
339
+ press.longPressFired = true;
340
+ dlog('synthesized longPress -> dispatch');
341
+ runWrapped(() => bubble(press.owner, LONG_PRESS, nativeEvent));
342
+ }, DEFAULT_LONG_PRESS_MS);
343
+ }
323
344
  }
324
345
  runWrapped(() => {
325
- bubble(instanceHandle, PRESS_IN, nativeEvent);
346
+ for (const stale of stalePresses)
347
+ bubble(stale.owner, PRESS_OUT, nativeEvent);
348
+ if (startedPress)
349
+ bubble(startedPress.owner, PRESS_IN, nativeEvent);
350
+ else
351
+ dlog('pressIn retained (another touch joined the active press)');
326
352
  // Responder negotiation runs alongside press synthesis: a View can be both
327
353
  // a Pressable (press) and a PanResponder target (responder).
328
354
  negotiateResponder(instanceHandle, 'start', nativeEvent);
@@ -335,16 +361,18 @@ export function installEventHandler() {
335
361
  if (topLevelType === TOUCH_MOVE) {
336
362
  recordTouchTrack('move', nativeEvent);
337
363
  attachTouchHistory(nativeEvent);
338
- // Cancel the pending long press if the touch drifted too far (Pressability's
339
- // deactivation-distance check). Skipped when either coord is unknown.
340
- if (longPressTimer !== undefined && longPressStart) {
364
+ // Only the press owning this move can lose its long-press timer; movement on an unrelated
365
+ // simultaneously held Pressable must not disturb another target's clock.
366
+ const movedPress = findActivePress(instanceHandle);
367
+ if (movedPress?.longPressTimer !== undefined &&
368
+ movedPress.longPressStart) {
341
369
  const here = readTouchPoint(nativeEvent);
342
370
  if (here) {
343
- const dx = here.x - longPressStart.x;
344
- const dy = here.y - longPressStart.y;
371
+ const dx = here.x - movedPress.longPressStart.x;
372
+ const dy = here.y - movedPress.longPressStart.y;
345
373
  if (Math.hypot(dx, dy) > LONG_PRESS_DEACTIVATION_DISTANCE) {
346
374
  dlog('longPress cancelled (moved past deactivation distance)');
347
- clearLongPress();
375
+ clearLongPress(movedPress);
348
376
  }
349
377
  }
350
378
  }
@@ -361,40 +389,45 @@ export function installEventHandler() {
361
389
  if (topLevelType === TOUCH_END) {
362
390
  recordTouchTrack('end', nativeEvent);
363
391
  attachTouchHistory(nativeEvent);
364
- const start = pressStart;
365
- pressStart = undefined;
392
+ const hadActivePress = activePresses.size > 0;
393
+ const completedPresses = [];
394
+ for (const press of activePresses) {
395
+ if (hasRemainingTouchWithin(press.owner, nativeEvent))
396
+ continue;
397
+ activePresses.delete(press);
398
+ clearLongPress(press);
399
+ completedPresses.push(press);
400
+ }
366
401
  const responder = currentResponder;
367
402
  // RN releases (and clears) the responder only when no remaining touch still down
368
403
  // started inside it; lifting ONE finger in a multi-touch gesture must NOT release.
369
404
  // onResponderEnd still fires on every finger-up. (ResponderEventPlugin: responderEnd
370
405
  // is unconditional, responderRelease is gated on noResponderTouches.)
371
406
  const releases = responder !== undefined &&
372
- !hasRemainingResponderTouch(responder, nativeEvent);
407
+ !hasRemainingTouchWithin(responder, nativeEvent);
373
408
  if (releases)
374
409
  currentResponder = undefined;
375
- // A completed long press eats the tap (RN), but pressOut still fires below.
376
- const wasLongPress = longPressFired;
377
- longPressFired = false;
378
- longPressStart = undefined;
379
- clearLongPress();
380
410
  runWrapped(() => {
381
- if (start) {
382
- // press fires only on an honest tap (ended within the responder); pressOut
383
- // always fires on the responder so its pressed-state can release.
384
- if (endsWithin(instanceHandle, start)) {
385
- if (wasLongPress) {
411
+ for (const press of completedPresses) {
412
+ // Each target completes independently. An honest tap ends inside that target; pressOut
413
+ // always releases its pressed state, including a drag-away end.
414
+ if (endsWithin(instanceHandle, press.owner)) {
415
+ if (press.longPressFired) {
386
416
  dlog('press suppressed (longPress already fired)');
387
417
  }
388
418
  else {
389
419
  dlog('event press -> dispatch');
390
- bubble(start, PRESS, nativeEvent);
420
+ bubble(press.owner, PRESS, nativeEvent);
391
421
  }
392
422
  }
393
- bubble(start, PRESS_OUT, nativeEvent);
423
+ bubble(press.owner, PRESS_OUT, nativeEvent);
394
424
  }
395
- else {
425
+ if (!hadActivePress) {
396
426
  dlog(`event ${TOUCH_END} ignored (no matching start)`);
397
427
  }
428
+ else if (completedPresses.length === 0) {
429
+ dlog('press retained (another touch remains inside its owner)');
430
+ }
398
431
  // onResponderEnd fires on every finger-up; onResponderRelease (the final
399
432
  // release) only when the last responder touch lifted.
400
433
  if (responder) {
@@ -413,20 +446,30 @@ export function installEventHandler() {
413
446
  if (topLevelType === TOUCH_CANCEL) {
414
447
  recordTouchTrack('end', nativeEvent);
415
448
  attachTouchHistory(nativeEvent);
416
- const start = pressStart;
417
- pressStart = undefined;
449
+ // A cancel is scoped to the finger(s) removed from `touches`, just like an end. An unrelated
450
+ // Pressable—or another finger under the same owner—must keep its press and long-press state.
451
+ const cancelledPresses = [];
452
+ for (const press of activePresses) {
453
+ if (hasRemainingTouchWithin(press.owner, nativeEvent))
454
+ continue;
455
+ activePresses.delete(press);
456
+ clearLongPress(press);
457
+ cancelledPresses.push(press);
458
+ }
418
459
  const responder = currentResponder;
419
- currentResponder = undefined;
420
- longPressFired = false;
421
- longPressStart = undefined;
422
- clearLongPress();
460
+ const terminatesResponder = responder !== undefined &&
461
+ !hasRemainingTouchWithin(responder, nativeEvent);
462
+ if (terminatesResponder)
463
+ currentResponder = undefined;
423
464
  runWrapped(() => {
424
- if (start)
425
- bubble(start, PRESS_OUT, nativeEvent);
426
- // A cancelled gesture ends then terminates (the responder was taken away).
465
+ for (const press of cancelledPresses)
466
+ bubble(press.owner, PRESS_OUT, nativeEvent);
427
467
  if (responder) {
468
+ // Like touch-end, every finger leaving emits responderEnd. Termination is final only
469
+ // when no touch remains inside the responder.
428
470
  callOwnListener(responder, RESPONDER_END, nativeEvent);
429
- callOwnListener(responder, RESPONDER_TERMINATE, nativeEvent);
471
+ if (terminatesResponder)
472
+ callOwnListener(responder, RESPONDER_TERMINATE, nativeEvent);
430
473
  }
431
474
  });
432
475
  if (touchHistory.numberActiveTouches === 0)
@@ -4,8 +4,8 @@
4
4
  // responsibilities stop sharing one 300+ line file. Color processing itself lives in
5
5
  // ./platform-color (the stable leaf every color-touching module imports from); this file only
6
6
  // decides WHICH props are color props and wires the structured CSS-style processors.
7
+ import { foldAriaProps } from './accessibility-props.js';
7
8
  import { RAW_TEXT_COMPONENT } from './node.js';
8
- import { flattenStyle } from './style/index.js';
9
9
  import { registeredProcessor } from './registry.js';
10
10
  import { isProcessableColor, processColor } from './platform-color/index.js';
11
11
  import { processBoxShadow } from './process-box-shadow/index.js';
@@ -164,29 +164,183 @@ function processValue(component, key, value) {
164
164
  return processColor(value);
165
165
  return value;
166
166
  }
167
+ // A style object is SHARED, and that is the one place this file has a complexity problem rather
168
+ // than a constant-factor one. StyleSheet.create hands out one frozen object per rule, and the CSS
169
+ // class registry resolves a class name to one cached object - so 1 000 rows carry the SAME handful
170
+ // of style objects, and resolving each one per node costs O(nodes x styleKeys) to compute an
171
+ // answer that only varies with O(distinct styles). Cache it on the style object's identity.
172
+ //
173
+ // Keyed by component as well: processValue consults that component's ViewConfig processors, so one
174
+ // style object can legitimately resolve differently under two view names.
175
+ //
176
+ // The cache assumes a style object is not MUTATED IN PLACE, which is already the engine's contract:
177
+ // setProp compares with Object.is and skips a same-identity write, so an in-place style edit never
178
+ // marks the node dirty and never reaches Fabric today either. What narrows slightly is the case
179
+ // where some OTHER prop on the same node changed in the same commit - that used to pick the
180
+ // mutation up as a side effect, and now does not.
181
+ //
182
+ // KEEPING undefined-valued keys is deliberate: the resolved object is a faithful picture of ONE
183
+ // style entry, and addStyle below needs to see an explicit `undefined` to let a later entry clear
184
+ // an earlier one. Dropping them here would silently turn `[{flex:1},{flex:undefined}]` into
185
+ // `flex: 1`.
186
+ const styleCache = new Map();
187
+ function processedStyle(component, style) {
188
+ let perComponent = styleCache.get(component);
189
+ if (perComponent === undefined) {
190
+ perComponent = new WeakMap();
191
+ styleCache.set(component, perComponent);
192
+ }
193
+ const cached = perComponent.get(style);
194
+ if (cached !== undefined)
195
+ return cached;
196
+ const resolved = {};
197
+ for (const key of Object.keys(style)) {
198
+ const value = style[key];
199
+ resolved[key] =
200
+ value === undefined ? undefined : processValue(component, key, value);
201
+ }
202
+ perComponent.set(style, resolved);
203
+ return resolved;
204
+ }
205
+ /**
206
+ * Hoist one style slot's keys into the payload being built, recursing on POSITION only - the same
207
+ * rule flattenStyle follows, and for the same reason: `transform: [{translateX: 5}]` is an
208
+ * array-VALUED prop, not a nested style.
209
+ *
210
+ * The point is that there is no intermediate object. Every style entry's resolution is memoized on
211
+ * its own identity and its keys are written straight into `out`, so a thousand rows sharing one
212
+ * class-resolved style resolve it ONCE and each node pays a copy loop.
213
+ *
214
+ * This is also the shape React Native itself uses. `ReactNativeAttributePayload.addNestedProperty`
215
+ * (.vendors/react/packages/react-native-renderer/src/ReactNativeAttributePayload.js:208) recurses
216
+ * over the style array writing into a single `updatePayload`; upstream's `flattenStyle` appears
217
+ * ONLY in `diffNestedProperty`, i.e. the update path where an array meets an object - never on
218
+ * create. Our previous version flattened first and hoisted second, which allocated one merged
219
+ * object per node per commit that nothing else ever read.
220
+ *
221
+ * It also fixed a dead cache. `processedStyle` used to be reachable only when `props.style` was a
222
+ * bare object, and it never is: `commitClassStyle` (node.ts) always writes the two-element
223
+ * `[classStyle, explicitStyle]` array, by design. So the memo existed, was correct, and never ran.
224
+ *
225
+ * Later entries win, because a later write overwrites the same key on `out`. An explicit
226
+ * `undefined` CLEARS the key instead, matching the flatten path it replaces. One narrow
227
+ * divergence, recorded rather than hidden: the `delete` also clears a same-named TOP-LEVEL prop
228
+ * hoisted before the style pass, which flattening did not. Style keys and native prop keys do not
229
+ * overlap in practice (one is Yoga/visual, the other is testID/accessibility/source), so this is
230
+ * theoretical - but it is a difference, and `fabric-props.test.ts` pins both halves.
231
+ */
232
+ function addStyle(out, component, style) {
233
+ if (Array.isArray(style)) {
234
+ for (const entry of style)
235
+ addStyle(out, component, entry);
236
+ return;
237
+ }
238
+ if (!isRecord(style))
239
+ return;
240
+ const resolved = processedStyle(component, style);
241
+ for (const key of Object.keys(resolved)) {
242
+ const value = resolved[key];
243
+ if (value === undefined)
244
+ delete out[key];
245
+ else
246
+ out[key] = value;
247
+ }
248
+ }
167
249
  // Translate the retained node's logical props into the flat payload Fabric's C++
168
250
  // props expect: `style` keys are hoisted to the top level, event handlers and
169
251
  // undefined values are dropped.
252
+ // RN HAS NO `value` FABRIC PROP. A TextInput's controlled value rides as the private `text` prop,
253
+ // and the fold that produces it — `value ?? defaultValue` — lives in the component wrapper
254
+ // (`core/components/src/view/render-text-input.ts`, whose own comment says "There is no `value`
255
+ // Fabric prop; this is the whole controlled surface"). A LOWERED element has no wrapper, so a
256
+ // transform printing the author's `value={x}` yields a key no ViewConfig declares: silently dropped,
257
+ // `text` never set, and the field renders EMPTY. Nothing red anywhere — found 2026-08-31 by an agent
258
+ // reading what the render function actually emits rather than trusting a header comment.
259
+ //
260
+ // So the fold moves to the layer every path goes through, exactly like the aria fold above it. This
261
+ // is the third instance of one rule: a lowered element inherits NOTHING its wrapper did, and the
262
+ // repair belongs below the fork, never in the transform.
263
+ //
264
+ // GATED ON THE COMPONENT, NOT ON THE PROP. `value` is also a prop of `Switch` and `Slider`; a fold
265
+ // keyed on the prop name would write a bogus `text` onto both. Two string comparisons rather than a
266
+ // Set lookup — this runs per node per commit, and the set has exactly two members.
267
+ //
268
+ // The engine may hold this because both views are in `BUILTIN_COMPONENTS`, whose hand-tuned tables
269
+ // (`view-config.ts`'s TEXT_INPUT_EVENTS, commit's COLOR_PROPS) already live here for the same
270
+ // reason. Routing it through `registerComponent` was tried first and is WRONG: `resolve()`
271
+ // short-circuits every builtin to EMPTY, so the registration would have been accepted and never
272
+ // applied.
273
+ const SINGLELINE_TEXT_INPUT = 'RCTSinglelineTextInputView';
274
+ const MULTILINE_TEXT_INPUT = 'RCTMultilineTextInputView';
275
+ function foldTextInputValue(props) {
276
+ const hasValue = props.value !== undefined;
277
+ const hasDefault = props.defaultValue !== undefined;
278
+ if (!hasValue && !hasDefault)
279
+ return props;
280
+ const folded = { ...props };
281
+ // `value` WINS over `defaultValue` — `foldText`'s rule, kept identical rather than re-derived.
282
+ // An explicit `text` is left alone: that is the component path, where the wrapper already folded,
283
+ // and re-folding there would let a stale `value` overwrite what the wrapper computed.
284
+ if (folded.text === undefined) {
285
+ folded.text = hasValue ? props.value : props.defaultValue;
286
+ }
287
+ // Blanked, not deleted: `fabricProps` skips undefined, and neither name is a real Fabric prop.
288
+ folded.value = undefined;
289
+ folded.defaultValue = undefined;
290
+ return folded;
291
+ }
170
292
  export function fabricProps(node) {
171
293
  if (node.component === RAW_TEXT_COMPONENT) {
172
294
  return { text: node.props.text };
173
295
  }
296
+ // This runs once per node per commit - 9 000 times on one benchmark press - so the two loops
297
+ // below iterate with Object.keys rather than Object.entries: entries allocates a fresh
298
+ // two-element array PER KEY on top of the outer array, and the resulting garbage was 18% of the
299
+ // create path in a CPU profile.
300
+ //
301
+ // Do NOT "improve" this to `for...in`. It was tried and reverted 2026-08-23. On paper it is the
302
+ // strictly cheaper shape - Object.keys allocates one array per call, 10 007 of them on a
303
+ // 1 000-row create (counted), and for...in allocates none - and the headless V8 bench agreed,
304
+ // 12-13% off create/replace `min`. On DEVICE it lost: with the Fabric call counts and prop-key
305
+ // payload byte-identical either way (9000/5000/1009, 32001 keys), Release Create went 217.8 ->
306
+ // 243.2 ms while stock moved only inside its 4% noise floor. Hermes' for-in is not V8's enum
307
+ // cache. The general rule this bought: an allocation-count win measured on V8 is not a Hermes
308
+ // win, and only the on-device number decides (`perf-claims-need-numbers`).
174
309
  const out = {};
175
- for (const [key, value] of Object.entries(node.props)) {
310
+ // THE ONE POINT WHERE THE WHOLE BAG IS KNOWN ON EVERY PATH, which is what the aria fold needs:
311
+ // `aria-checked` has to be folded against a sibling `accessibilityState`, and `routeProp` sees
312
+ // one key at a time. Both commit paths — create and update — reach here, so a lowered element
313
+ // gets the fold it has no wrapper to run.
314
+ //
315
+ // NOT memoised on `node.props` identity. That object is stable and mutated IN PLACE, so an
316
+ // identity-keyed cache (the `processedStyle` pattern below) would be stale forever. The gate is
317
+ // the node's sticky flag instead: one boolean read for a node with no alias, which is nearly all
318
+ // of them, and the fold's own fast path returns by identity for the rest.
319
+ const aliasFolded = node.hasAriaAlias
320
+ ? foldAriaProps(node.props)
321
+ : node.props;
322
+ // The behavior's own fold, for a LOWERED element only — the two folds above are keyed on the
323
+ // component name, which a wrapper and its lowered twin share, so neither could carry a
324
+ // per-primitive fold without running it twice on the wrapper. See IPayloadFold.
325
+ const behaviorFolded = node.payloadFold !== undefined
326
+ ? node.payloadFold(aliasFolded)
327
+ : aliasFolded;
328
+ const props = node.component === SINGLELINE_TEXT_INPUT ||
329
+ node.component === MULTILINE_TEXT_INPUT
330
+ ? foldTextInputValue(behaviorFolded)
331
+ : behaviorFolded;
332
+ for (const key of Object.keys(props)) {
176
333
  if (key === 'style')
177
334
  continue;
335
+ const value = props[key];
178
336
  if (typeof value === 'function')
179
337
  continue;
180
338
  if (value === undefined)
181
339
  continue;
182
340
  out[key] = processValue(node.component, key, value);
183
341
  }
184
- // Collapse style (object | array | nested arrays) into one flat payload before
185
- // hoisting: `style={[base, override]}` is RN's idiom and Fabric wants it flat.
186
- const style = flattenStyle(node.props.style);
187
- for (const [key, value] of Object.entries(style)) {
188
- if (value !== undefined)
189
- out[key] = processValue(node.component, key, value);
190
- }
342
+ // Hoist the style slot (object | array | nested arrays) into the SAME payload object - no
343
+ // intermediate flatten. See addStyle for the shape and for the two things this fixed.
344
+ addStyle(out, node.component, props.style);
191
345
  return out;
192
346
  }
package/build/fabric.d.ts CHANGED
@@ -13,8 +13,9 @@ export type IMeasureLayoutOnSuccess = (left: number, top: number, width: number,
13
13
  export interface IFabricSlot {
14
14
  createNode(reactTag: number, viewName: string, rootTag: IRootTag, props: IFabricProps, instanceHandle: unknown): IFabricNode;
15
15
  cloneNodeWithNewProps(node: IFabricNode, newProps: IFabricProps): IFabricNode;
16
- cloneNodeWithNewChildren(node: IFabricNode): IFabricNode;
17
- cloneNodeWithNewChildrenAndProps(node: IFabricNode, newProps: IFabricProps): IFabricNode;
16
+ cloneNodeWithNewChildren(node: IFabricNode, children?: readonly IFabricNode[]): IFabricNode;
17
+ cloneNodeWithNewChildrenAndProps(node: IFabricNode, newProps: IFabricProps, children?: readonly IFabricNode[]): IFabricNode;
18
+ supportsCloneWithChildren: boolean;
18
19
  createChildSet(rootTag: IRootTag): IFabricChildSet;
19
20
  appendChild(parent: IFabricNode, child: IFabricNode): IFabricNode;
20
21
  appendChildToSet(childSet: IFabricChildSet, child: IFabricNode): void;
@@ -26,7 +27,13 @@ export interface IFabricSlot {
26
27
  measureInWindow(node: IFabricNode, callback: IMeasureInWindowOnSuccess): void;
27
28
  measureLayout(node: IFabricNode, relativeToNode: IFabricNode, onFail: () => void, onSuccess: IMeasureLayoutOnSuccess): void;
28
29
  }
30
+ interface IFabricHost extends Omit<IFabricSlot, 'cloneNodeWithNewChildren' | 'cloneNodeWithNewChildrenAndProps' | 'supportsCloneWithChildren'> {
31
+ cloneNodeWithNewChildren(node: IFabricNode, children?: readonly IFabricNode[]): IFabricNode;
32
+ cloneNodeWithNewChildrenAndProps(node: IFabricNode, newProps: IFabricProps): IFabricNode;
33
+ cloneNodeWithNewChildrenAndProps(node: IFabricNode, children: readonly IFabricNode[], newProps: IFabricProps): IFabricNode;
34
+ }
29
35
  declare global {
30
- var nativeFabricUIManager: IFabricSlot | undefined;
36
+ var nativeFabricUIManager: IFabricHost | undefined;
31
37
  }
32
38
  export declare function getSlot(): IFabricSlot;
39
+ export {};
package/build/fabric.js CHANGED
@@ -35,8 +35,17 @@ export function getSlot() {
35
35
  cached = {
36
36
  createNode: (reactTag, viewName, rootTag, props, instanceHandle) => createNode(reactTag, viewName, rootTag, props, instanceHandle),
37
37
  cloneNodeWithNewProps: (node, newProps) => cloneNodeWithNewProps(node, newProps),
38
- cloneNodeWithNewChildren: node => cloneNodeWithNewChildren(node),
39
- cloneNodeWithNewChildrenAndProps: (node, newProps) => cloneNodeWithNewChildrenAndProps(node, newProps),
38
+ // The host's 3-arg form is (node, children, props); ours keeps props second.
39
+ cloneNodeWithNewChildren: (node, children) => children === undefined
40
+ ? cloneNodeWithNewChildren(node)
41
+ : cloneNodeWithNewChildren(node, children),
42
+ cloneNodeWithNewChildrenAndProps: (node, newProps, children) => children === undefined
43
+ ? cloneNodeWithNewChildrenAndProps(node, newProps)
44
+ : cloneNodeWithNewChildrenAndProps(node, children, newProps),
45
+ supportsCloneWithChildren: typeof cloneNodeWithNewChildren === 'function' &&
46
+ cloneNodeWithNewChildren.length >= 2 &&
47
+ typeof cloneNodeWithNewChildrenAndProps === 'function' &&
48
+ cloneNodeWithNewChildrenAndProps.length >= 3,
40
49
  createChildSet: rootTag => createChildSet(rootTag),
41
50
  appendChild: (parent, child) => appendChild(parent, child),
42
51
  appendChildToSet: (childSet, child) => appendChildToSet(childSet, child),
@@ -0,0 +1,47 @@
1
+ import type { ISymbioteNode } from './node';
2
+ /**
3
+ * A pure props -> props mapping a behavior applies on the way to the Fabric payload.
4
+ *
5
+ * It exists because a lowered element has no component body, and a wrapper's body is where the
6
+ * per-primitive prop FOLDS live — TextInput's W3C aliases (`inputMode` -> `keyboardType`,
7
+ * `readOnly` -> `editable`), Pressable's `disabled` -> `accessibilityState`. Every one of those was
8
+ * silently dropped the moment the primitive lowered: the raw alias reached Fabric as a key no
9
+ * ViewConfig declares, so nothing threw and nothing rendered differently in a headless test —
10
+ * only the device showed a numeric keyboard that never appeared.
11
+ *
12
+ * NOT a hook on `setProp`, for the same reason `afterCommit` is not: `setProp` is the hottest path
13
+ * in the engine. This runs once per node per payload build, and only for a node whose behavior
14
+ * supplied one.
15
+ *
16
+ * MUST be pure and MUST NOT mutate its input — `node.props` is the live bag, and the folds beside
17
+ * this one return their input by identity when there is nothing to do.
18
+ */
19
+ export type IPayloadFold = (props: Readonly<Record<string, unknown>>) => Record<string, unknown>;
20
+ export interface IHostBehavior {
21
+ readonly ownedListeners?: readonly string[];
22
+ attach(node: ISymbioteNode): void;
23
+ attachAfterCommit?(node: ISymbioteNode): void;
24
+ afterCommit?(node: ISymbioteNode): void;
25
+ detach(node: ISymbioteNode): void;
26
+ readonly foldPayload?: IPayloadFold;
27
+ }
28
+ export declare function registerHostBehavior(component: string, behavior: IHostBehavior): void;
29
+ export declare function hostBehaviorFor(tag: string): IHostBehavior | undefined;
30
+ export declare function hasHostBehaviors(): boolean;
31
+ export declare function ownsListener(node: ISymbioteNode, name: string): boolean;
32
+ export declare function stashAppListener(node: ISymbioteNode, name: string, listener: unknown): void;
33
+ export declare function appListenerFor(node: ISymbioteNode, name: string): unknown;
34
+ export declare function attachHostBehavior(node: ISymbioteNode, tag: string): void;
35
+ /**
36
+ * Run the deferred half of every behavior whose node has now been committed. Called from the commit
37
+ * path immediately after `completeRoot`, where fresh Fabric tags have just been assigned.
38
+ *
39
+ * `isCommitted` is passed in for the same no-cycle reason — `committedOf` lives in `commit.ts`. A
40
+ * still-uncommitted node stays in the set: a create superseded before it ever reached Fabric waits
41
+ * for the commit that lands it, and `detachSubtree` drops it if that commit never comes.
42
+ */
43
+ export declare function runDeferredAttaches(isCommitted: (node: ISymbioteNode) => boolean): void;
44
+ export declare function markDetachCandidate(node: ISymbioteNode): void;
45
+ export declare function sweepDetachedBehaviors(topLevel: readonly ISymbioteNode[]): void;
46
+ export declare function reattachHostBehaviors(node: ISymbioteNode): void;
47
+ export declare function clearHostBehaviors(): void;