@farm.js/react 0.1.0-beta.25 → 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.
@@ -2618,18 +2618,21 @@ function commitKeyedRowBinding(binding, instance, bindingIndex, value, target) {
2618
2618
  instance.values[bindingIndex] = value;
2619
2619
  if (!target) return;
2620
2620
  if (binding.kind === "text") {
2621
- const text = target.firstChild;
2622
- if (value && text && text === target.lastChild && text.nodeType === 3) {
2623
- text.data = value;
2624
- } else {
2625
- target.textContent = value;
2626
- }
2621
+ updateTextContent(target, value);
2627
2622
  } else if (binding.kind === "style" && binding.name) {
2628
2623
  updateStyle(target, binding.name, value);
2629
2624
  } else if (binding.kind === "attribute" && binding.name) {
2630
2625
  updateAttribute(target, binding.name, value);
2631
2626
  }
2632
2627
  }
2628
+ function updateTextContent(target, value) {
2629
+ const text = target.firstChild;
2630
+ if (value && text && text === target.lastChild && text.nodeType === 3) {
2631
+ text.data = value;
2632
+ } else {
2633
+ target.textContent = value;
2634
+ }
2635
+ }
2633
2636
  function prepareKeyedRowBindingUpdate(props, instance, item, index, bindingIndex) {
2634
2637
  const binding = props.bindings[bindingIndex];
2635
2638
  const rawValue = binding.read(item, index);
@@ -8314,6 +8317,7 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8314
8317
  this.trackedBindingsByDependency = [];
8315
8318
  this.trackedDependenciesByBinding = /* @__PURE__ */ new Map();
8316
8319
  this.bindingValues = /* @__PURE__ */ new Map();
8320
+ this.textNodes = /* @__PURE__ */ new Map();
8317
8321
  this.activeBinding = null;
8318
8322
  this.activeDependencies = null;
8319
8323
  this.renderedDefinition = null;
@@ -8376,13 +8380,8 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8376
8380
  }
8377
8381
  this.blockRuntime = blockRuntime;
8378
8382
  }
8379
- usesHybridReactivity() {
8380
- return definitionReference.current.reactivity === "hybrid";
8381
- }
8382
8383
  canReuseRenderedElement(currentDefinition, propValues) {
8383
- return Boolean(
8384
- this.mounted && propValues && propValues.every(isCompilerPrimitive) && this.renderedDefinition === currentDefinition && this.renderedElement
8385
- );
8384
+ return this.mounted && propValues !== null && propValues.every(isCompilerPrimitive) && this.renderedDefinition === currentDefinition;
8386
8385
  }
8387
8386
  renderCellsForProps(propValues) {
8388
8387
  if (!propValues) return { cells: this.cells, commit: () => void 0 };
@@ -8404,7 +8403,7 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8404
8403
  };
8405
8404
  }
8406
8405
  tracksBinding(binding) {
8407
- return this.usesHybridReactivity() && binding.tracking === "dynamic";
8406
+ return definitionReference.current.reactivity === "hybrid" && binding.tracking === "dynamic";
8408
8407
  }
8409
8408
  ensureBindingIndex() {
8410
8409
  const currentDefinition = definitionReference.current;
@@ -8466,7 +8465,7 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8466
8465
  return binding.kind === "text" ? renderTextValue(value) : value;
8467
8466
  }
8468
8467
  primeHybridBindings() {
8469
- if (!this.usesHybridReactivity()) return;
8468
+ if (definitionReference.current.reactivity !== "hybrid") return;
8470
8469
  for (const binding of definitionReference.current.bindings) {
8471
8470
  if (binding.kind === "block") continue;
8472
8471
  if (!this.tracksBinding(binding)) continue;
@@ -8555,29 +8554,26 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8555
8554
  for (const binding of this.staticBindingsByDependency[dependency] || []) {
8556
8555
  affectedBindings.add(binding);
8557
8556
  }
8558
- if (this.usesHybridReactivity()) {
8557
+ if (definitionReference.current.reactivity === "hybrid") {
8559
8558
  for (const binding of this.trackedBindingsByDependency[dependency] || []) {
8560
8559
  affectedBindings.add(binding);
8561
8560
  }
8562
8561
  }
8563
8562
  }
8564
- const hasAffectedMountedAncestor = (binding) => {
8563
+ const blockRefreshes = [];
8564
+ for (const id of affectedBlockIds) {
8565
+ const binding = this.blockBindings.get(id);
8566
+ const refresh = this.blockRefreshListeners.get(id);
8567
+ if (!binding || !refresh) continue;
8565
8568
  let parent = binding.parent;
8566
8569
  while (parent !== void 0) {
8567
- if (affectedBlockIds.has(parent) && this.blockRefreshListeners.has(parent)) {
8568
- return true;
8569
- }
8570
+ if (affectedBlockIds.has(parent) && this.blockRefreshListeners.has(parent)) break;
8570
8571
  parent = this.blockBindings.get(parent)?.parent;
8571
8572
  }
8572
- return false;
8573
- };
8574
- const blockRefreshes = [...affectedBlockIds].map((id) => {
8575
- const binding = this.blockBindings.get(id);
8576
- const refresh = this.blockRefreshListeners.get(id);
8577
- return binding && refresh && !hasAffectedMountedAncestor(binding) ? refresh : void 0;
8578
- }).filter((refresh) => refresh !== void 0);
8573
+ if (parent === void 0) blockRefreshes.push(refresh);
8574
+ }
8579
8575
  for (const binding of affectedBindings) {
8580
- if (binding.kind !== "block") this.applyBinding(binding);
8576
+ this.applyBinding(binding);
8581
8577
  }
8582
8578
  let pendingBlockCommits = blockRefreshes.length;
8583
8579
  for (const refresh of blockRefreshes) {
@@ -8603,7 +8599,12 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8603
8599
  if (Object.is(this.bindingValues.get(binding), comparableValue)) return;
8604
8600
  }
8605
8601
  if (binding.kind === "text") {
8606
- target.textContent = comparableValue;
8602
+ if (!this.textNodes.has(target)) {
8603
+ this.textNodes.set(target, [...target.childNodes]);
8604
+ target.textContent = comparableValue;
8605
+ } else {
8606
+ updateTextContent(target, comparableValue);
8607
+ }
8607
8608
  } else if (binding.kind === "style") {
8608
8609
  updateStyle(target, binding.name, value);
8609
8610
  } else {
@@ -8620,9 +8621,16 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8620
8621
  getSnapshotBeforeUpdate() {
8621
8622
  const currentDefinition = definitionReference.current;
8622
8623
  const propValues = currentDefinition.readProps?.(this.props) || null;
8623
- return this.canReuseRenderedElement(currentDefinition, propValues);
8624
+ if (this.canReuseRenderedElement(currentDefinition, propValues)) return true;
8625
+ this.textNodes.forEach((children, target) => {
8626
+ target.textContent = "";
8627
+ for (const child of children) target.appendChild(child);
8628
+ });
8629
+ this.textNodes.clear();
8630
+ this.bindingValues.clear();
8631
+ return false;
8624
8632
  }
8625
- componentDidUpdate(_previousProps, _previousState, reusedRenderedElement = false) {
8633
+ componentDidUpdate(_previousProps, _previousState, reusedRenderedElement) {
8626
8634
  const propValues = definitionReference.current.readProps?.(this.props) || null;
8627
8635
  if (propValues) {
8628
8636
  if (reusedRenderedElement) this.captureInputSelection();
@@ -8637,12 +8645,16 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8637
8645
  cell.flush();
8638
8646
  }
8639
8647
  }
8648
+ if (!reusedRenderedElement) {
8649
+ this.ensureBindingIndex();
8650
+ this.primeHybridBindings();
8651
+ }
8640
8652
  this.flushBindingUpdates();
8641
8653
  return;
8642
8654
  }
8643
8655
  this.ensureBindingIndex();
8644
8656
  for (const binding of definitionReference.current.bindings) {
8645
- if (binding.kind !== "block") this.applyBinding(binding, true);
8657
+ this.applyBinding(binding, true);
8646
8658
  }
8647
8659
  }
8648
8660
  componentWillUnmount() {
@@ -8658,6 +8670,7 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8658
8670
  this.trackedBindingsByDependency = [];
8659
8671
  this.trackedDependenciesByBinding.clear();
8660
8672
  this.bindingValues.clear();
8673
+ this.textNodes.clear();
8661
8674
  this.activeBinding = null;
8662
8675
  this.activeDependencies = null;
8663
8676
  refreshListeners.delete(this.refreshDefinition);