@farm.js/react 0.1.0-beta.24 → 0.1.0-beta.26

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/README.md CHANGED
@@ -295,6 +295,12 @@ and keyed-target fast paths, not support for other state changes: opaque updates
295
295
  still use complete keyed reconciliation. Mixed hints, targeted bindings, conditional rows, and host
296
296
  blocks keep their existing runtime. No additional option is required.
297
297
 
298
+ The same component-wide proof selects a smaller removal-only runtime when the only emitted
299
+ update hints are `filter()` and/or `slice()`. It omits unused append, map-update, and keyed-target
300
+ fast paths while retaining complete keyed reconciliation for opaque updates or rejected hints.
301
+ A sibling list requiring broader hints, targeted bindings, conditional rows, or host blocks keeps
302
+ the existing combined runtime. This changes bundle selection, not native array or React semantics.
303
+
298
304
  Adjacent removal and append setters can share the same committed-row proof:
299
305
 
300
306
  ```tsx
@@ -380,6 +386,13 @@ positions into the prepend. The runtime removes only rejected rows, preserves ev
380
386
  node, and creates only the final prefix instead of rescanning and rebinding the whole result.
381
387
  Multiple adjacent prepends share the same proof.
382
388
 
389
+ When every keyed list in a component is plain and has no targeted bindings, and prepend is
390
+ the only emitted update hint, Farm selects a smaller prepend-only runtime. It omits unused
391
+ target and map/append fast paths, but keeps the same prepend validation and complete keyed
392
+ reconciliation for opaque or rejected updates. Mixed hints, conditional/host rows, and targeted
393
+ bindings on any sibling list keep their existing runtime. This changes bundle size, not the
394
+ supported update semantics or the prepend algorithm.
395
+
383
396
  The setter may be concise or use a block containing exactly one direct value-returning `return`.
384
397
  Extra statements, conditional returns, and missing returns keep complete keyed reconciliation.
385
398
 
@@ -177,7 +177,8 @@ function compilerKeyedArrayFilterSurvivorsFromUpdate(update, sourceToken, expect
177
177
  if (current.sourceToken !== sourceToken) return void 0;
178
178
  updates.push(current);
179
179
  }
180
- let survivors = Array.from({ length: expectedLength }, (_, index) => index);
180
+ let survivors = new Array(expectedLength);
181
+ for (let index = 0; index < expectedLength; index += 1) survivors[index] = index;
181
182
  let keysStable = true;
182
183
  for (let updateIndex = updates.length - 1; updateIndex >= 0; updateIndex -= 1) {
183
184
  const current = updates[updateIndex];
@@ -2623,18 +2624,21 @@ function commitKeyedRowBinding(binding, instance, bindingIndex, value, target) {
2623
2624
  instance.values[bindingIndex] = value;
2624
2625
  if (!target) return;
2625
2626
  if (binding.kind === "text") {
2626
- const text = target.firstChild;
2627
- if (value && text && text === target.lastChild && text.nodeType === 3) {
2628
- text.data = value;
2629
- } else {
2630
- target.textContent = value;
2631
- }
2627
+ updateTextContent(target, value);
2632
2628
  } else if (binding.kind === "style" && binding.name) {
2633
2629
  updateStyle(target, binding.name, value);
2634
2630
  } else if (binding.kind === "attribute" && binding.name) {
2635
2631
  updateAttribute(target, binding.name, value);
2636
2632
  }
2637
2633
  }
2634
+ function updateTextContent(target, value) {
2635
+ const text = target.firstChild;
2636
+ if (value && text && text === target.lastChild && text.nodeType === 3) {
2637
+ text.data = value;
2638
+ } else {
2639
+ target.textContent = value;
2640
+ }
2641
+ }
2638
2642
  function prepareKeyedRowBindingUpdate(props, instance, item, index, bindingIndex) {
2639
2643
  const binding = props.bindings[bindingIndex];
2640
2644
  const rawValue = binding.read(item, index);
@@ -2645,17 +2649,34 @@ function prepareKeyedRowBindingUpdate(props, instance, item, index, bindingIndex
2645
2649
  return [bindingIndex, target, value];
2646
2650
  }
2647
2651
  function prepareKeyedRowBindingUpdates(props, instance, item, index) {
2652
+ let first;
2648
2653
  let updates;
2649
2654
  for (let bindingIndex = 0; bindingIndex < props.bindings.length; bindingIndex += 1) {
2650
2655
  const update = prepareKeyedRowBindingUpdate(props, instance, item, index, bindingIndex);
2651
2656
  if (update === void 0) return void 0;
2652
- if (update) (updates || (updates = [])).push(update);
2657
+ if (update) {
2658
+ if (updates) updates.push(update);
2659
+ else if (first) {
2660
+ updates = [];
2661
+ updates.push(first);
2662
+ updates.push(update);
2663
+ } else first = update;
2664
+ }
2653
2665
  }
2654
- return updates || NO_KEYED_ROW_BINDING_UPDATES;
2666
+ return updates || first || NO_KEYED_ROW_BINDING_UPDATES;
2655
2667
  }
2656
2668
  var NO_KEYED_ROW_BINDING_UPDATES = [];
2657
2669
  function applyPreparedKeyedRowBindingUpdates(props, instance, updates) {
2658
- for (const [bindingIndex, target, value] of updates) {
2670
+ if (typeof updates[0] === "number") {
2671
+ const [bindingIndex, target, value] = updates;
2672
+ commitKeyedRowBinding(props.bindings[bindingIndex], instance, bindingIndex, value, target);
2673
+ return;
2674
+ }
2675
+ for (const [
2676
+ bindingIndex,
2677
+ target,
2678
+ value
2679
+ ] of updates) {
2659
2680
  commitKeyedRowBinding(props.bindings[bindingIndex], instance, bindingIndex, value, target);
2660
2681
  }
2661
2682
  }
@@ -4446,6 +4467,12 @@ var keyedPrependUpdateRuntime = {
4446
4467
  ...keyedUpdateRuntime,
4447
4468
  prepend: reconcileCompilerKeyedArrayPrepend
4448
4469
  };
4470
+ var keyedPrependOnlyUpdateRuntime = {
4471
+ append: () => void 0,
4472
+ commit: commitCompilerKeyedCollection,
4473
+ reconcile: () => void 0,
4474
+ prepend: reconcileCompilerKeyedArrayPrepend
4475
+ };
4449
4476
  var keyedFilterPrependUpdateRuntime = {
4450
4477
  ...keyedFilterUpdateRuntime,
4451
4478
  prepend: reconcileCompilerKeyedArrayPrepend
@@ -7652,6 +7679,14 @@ var keyedRowsFilterHintedRuntimeFeature = {
7652
7679
  })
7653
7680
  })
7654
7681
  };
7682
+ var keyedRowsFilterOnlyRuntimeFeature = {
7683
+ name: "keyed-rows:filter-only",
7684
+ create: (owner) => ({
7685
+ KeyedRows: createKeyedRowsBlockComponentCore(owner, {
7686
+ keyedUpdates: keyedFilterOnlyUpdateRuntime
7687
+ })
7688
+ })
7689
+ };
7655
7690
  var keyedRowsIdentityFilterHintedRuntimeFeature = {
7656
7691
  name: "keyed-rows:identity-filter-hinted",
7657
7692
  create: (owner) => ({
@@ -7710,6 +7745,14 @@ var keyedRowsPrependHintedRuntimeFeature = {
7710
7745
  })
7711
7746
  })
7712
7747
  };
7748
+ var keyedRowsPrependOnlyRuntimeFeature = {
7749
+ name: "keyed-rows:prepend-only",
7750
+ create: (owner) => ({
7751
+ KeyedRows: createKeyedRowsBlockComponentCore(owner, {
7752
+ keyedUpdates: keyedPrependOnlyUpdateRuntime
7753
+ })
7754
+ })
7755
+ };
7713
7756
  var keyedRowsFilterPrependHintedRuntimeFeature = {
7714
7757
  name: "keyed-rows:filter-prepend-hinted",
7715
7758
  create: (owner) => ({
@@ -8280,6 +8323,7 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8280
8323
  this.trackedBindingsByDependency = [];
8281
8324
  this.trackedDependenciesByBinding = /* @__PURE__ */ new Map();
8282
8325
  this.bindingValues = /* @__PURE__ */ new Map();
8326
+ this.textNodes = /* @__PURE__ */ new Map();
8283
8327
  this.activeBinding = null;
8284
8328
  this.activeDependencies = null;
8285
8329
  this.renderedDefinition = null;
@@ -8342,13 +8386,8 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8342
8386
  }
8343
8387
  this.blockRuntime = blockRuntime;
8344
8388
  }
8345
- usesHybridReactivity() {
8346
- return definitionReference.current.reactivity === "hybrid";
8347
- }
8348
8389
  canReuseRenderedElement(currentDefinition, propValues) {
8349
- return Boolean(
8350
- this.mounted && propValues && propValues.every(isCompilerPrimitive) && this.renderedDefinition === currentDefinition && this.renderedElement
8351
- );
8390
+ return this.mounted && propValues !== null && propValues.every(isCompilerPrimitive) && this.renderedDefinition === currentDefinition;
8352
8391
  }
8353
8392
  renderCellsForProps(propValues) {
8354
8393
  if (!propValues) return { cells: this.cells, commit: () => void 0 };
@@ -8370,7 +8409,7 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8370
8409
  };
8371
8410
  }
8372
8411
  tracksBinding(binding) {
8373
- return this.usesHybridReactivity() && binding.tracking === "dynamic";
8412
+ return definitionReference.current.reactivity === "hybrid" && binding.tracking === "dynamic";
8374
8413
  }
8375
8414
  ensureBindingIndex() {
8376
8415
  const currentDefinition = definitionReference.current;
@@ -8432,7 +8471,7 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8432
8471
  return binding.kind === "text" ? renderTextValue(value) : value;
8433
8472
  }
8434
8473
  primeHybridBindings() {
8435
- if (!this.usesHybridReactivity()) return;
8474
+ if (definitionReference.current.reactivity !== "hybrid") return;
8436
8475
  for (const binding of definitionReference.current.bindings) {
8437
8476
  if (binding.kind === "block") continue;
8438
8477
  if (!this.tracksBinding(binding)) continue;
@@ -8521,29 +8560,26 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8521
8560
  for (const binding of this.staticBindingsByDependency[dependency] || []) {
8522
8561
  affectedBindings.add(binding);
8523
8562
  }
8524
- if (this.usesHybridReactivity()) {
8563
+ if (definitionReference.current.reactivity === "hybrid") {
8525
8564
  for (const binding of this.trackedBindingsByDependency[dependency] || []) {
8526
8565
  affectedBindings.add(binding);
8527
8566
  }
8528
8567
  }
8529
8568
  }
8530
- const hasAffectedMountedAncestor = (binding) => {
8569
+ const blockRefreshes = [];
8570
+ for (const id of affectedBlockIds) {
8571
+ const binding = this.blockBindings.get(id);
8572
+ const refresh = this.blockRefreshListeners.get(id);
8573
+ if (!binding || !refresh) continue;
8531
8574
  let parent = binding.parent;
8532
8575
  while (parent !== void 0) {
8533
- if (affectedBlockIds.has(parent) && this.blockRefreshListeners.has(parent)) {
8534
- return true;
8535
- }
8576
+ if (affectedBlockIds.has(parent) && this.blockRefreshListeners.has(parent)) break;
8536
8577
  parent = this.blockBindings.get(parent)?.parent;
8537
8578
  }
8538
- return false;
8539
- };
8540
- const blockRefreshes = [...affectedBlockIds].map((id) => {
8541
- const binding = this.blockBindings.get(id);
8542
- const refresh = this.blockRefreshListeners.get(id);
8543
- return binding && refresh && !hasAffectedMountedAncestor(binding) ? refresh : void 0;
8544
- }).filter((refresh) => refresh !== void 0);
8579
+ if (parent === void 0) blockRefreshes.push(refresh);
8580
+ }
8545
8581
  for (const binding of affectedBindings) {
8546
- if (binding.kind !== "block") this.applyBinding(binding);
8582
+ this.applyBinding(binding);
8547
8583
  }
8548
8584
  let pendingBlockCommits = blockRefreshes.length;
8549
8585
  for (const refresh of blockRefreshes) {
@@ -8569,7 +8605,12 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8569
8605
  if (Object.is(this.bindingValues.get(binding), comparableValue)) return;
8570
8606
  }
8571
8607
  if (binding.kind === "text") {
8572
- target.textContent = comparableValue;
8608
+ if (!this.textNodes.has(target)) {
8609
+ this.textNodes.set(target, [...target.childNodes]);
8610
+ target.textContent = comparableValue;
8611
+ } else {
8612
+ updateTextContent(target, comparableValue);
8613
+ }
8573
8614
  } else if (binding.kind === "style") {
8574
8615
  updateStyle(target, binding.name, value);
8575
8616
  } else {
@@ -8586,9 +8627,16 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8586
8627
  getSnapshotBeforeUpdate() {
8587
8628
  const currentDefinition = definitionReference.current;
8588
8629
  const propValues = currentDefinition.readProps?.(this.props) || null;
8589
- return this.canReuseRenderedElement(currentDefinition, propValues);
8630
+ if (this.canReuseRenderedElement(currentDefinition, propValues)) return true;
8631
+ this.textNodes.forEach((children, target) => {
8632
+ target.textContent = "";
8633
+ for (const child of children) target.appendChild(child);
8634
+ });
8635
+ this.textNodes.clear();
8636
+ this.bindingValues.clear();
8637
+ return false;
8590
8638
  }
8591
- componentDidUpdate(_previousProps, _previousState, reusedRenderedElement = false) {
8639
+ componentDidUpdate(_previousProps, _previousState, reusedRenderedElement) {
8592
8640
  const propValues = definitionReference.current.readProps?.(this.props) || null;
8593
8641
  if (propValues) {
8594
8642
  if (reusedRenderedElement) this.captureInputSelection();
@@ -8603,12 +8651,16 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8603
8651
  cell.flush();
8604
8652
  }
8605
8653
  }
8654
+ if (!reusedRenderedElement) {
8655
+ this.ensureBindingIndex();
8656
+ this.primeHybridBindings();
8657
+ }
8606
8658
  this.flushBindingUpdates();
8607
8659
  return;
8608
8660
  }
8609
8661
  this.ensureBindingIndex();
8610
8662
  for (const binding of definitionReference.current.bindings) {
8611
- if (binding.kind !== "block") this.applyBinding(binding, true);
8663
+ this.applyBinding(binding, true);
8612
8664
  }
8613
8665
  }
8614
8666
  componentWillUnmount() {
@@ -8624,6 +8676,7 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8624
8676
  this.trackedBindingsByDependency = [];
8625
8677
  this.trackedDependenciesByBinding.clear();
8626
8678
  this.bindingValues.clear();
8679
+ this.textNodes.clear();
8627
8680
  this.activeBinding = null;
8628
8681
  this.activeDependencies = null;
8629
8682
  refreshListeners.delete(this.refreshDefinition);
@@ -8785,6 +8838,7 @@ exports.keyedRowsConditionalWindowEveryHintedRuntimeFeature = keyedRowsCondition
8785
8838
  exports.keyedRowsConditionalWindowPositionHintedRuntimeFeature = keyedRowsConditionalWindowPositionHintedRuntimeFeature;
8786
8839
  exports.keyedRowsEveryHintedRuntimeFeature = keyedRowsEveryHintedRuntimeFeature;
8787
8840
  exports.keyedRowsFilterHintedRuntimeFeature = keyedRowsFilterHintedRuntimeFeature;
8841
+ exports.keyedRowsFilterOnlyRuntimeFeature = keyedRowsFilterOnlyRuntimeFeature;
8788
8842
  exports.keyedRowsFilterPrependHintedRuntimeFeature = keyedRowsFilterPrependHintedRuntimeFeature;
8789
8843
  exports.keyedRowsHintedRuntimeFeature = keyedRowsHintedRuntimeFeature;
8790
8844
  exports.keyedRowsHostAllHintedRuntimeFeature = keyedRowsHostAllHintedRuntimeFeature;
@@ -8815,6 +8869,7 @@ exports.keyedRowsMembershipRuntimeFeature = keyedRowsMembershipRuntimeFeature;
8815
8869
  exports.keyedRowsPlainRuntimeFeature = keyedRowsPlainRuntimeFeature;
8816
8870
  exports.keyedRowsPositionHintedRuntimeFeature = keyedRowsPositionHintedRuntimeFeature;
8817
8871
  exports.keyedRowsPrependHintedRuntimeFeature = keyedRowsPrependHintedRuntimeFeature;
8872
+ exports.keyedRowsPrependOnlyRuntimeFeature = keyedRowsPrependOnlyRuntimeFeature;
8818
8873
  exports.keyedRowsReorderHintedRuntimeFeature = keyedRowsReorderHintedRuntimeFeature;
8819
8874
  exports.keyedRowsRuntimeFeature = keyedRowsRuntimeFeature;
8820
8875
  exports.keyedRowsStructuralAppendHintedRuntimeFeature = keyedRowsStructuralAppendHintedRuntimeFeature;