@farm.js/react 0.1.0-beta.36 → 0.1.0-beta.38

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
@@ -119,6 +119,11 @@ The current compiler handles components that it can prove have:
119
119
  - React-managed event handlers; and
120
120
  - no refs, effects, or unsupported dynamic child structures.
121
121
 
122
+ State-dependent event handler selection, such as `onClick={active ? save : cancel}`, keeps the
123
+ component on React's normal rendering path so replacing, adding, or removing a callback updates
124
+ React's event props. Direct inline handlers that read state when invoked, such as
125
+ `onClick={() => save(active)}`, retain the existing compiled path when otherwise eligible.
126
+
122
127
  The generated component preserves React ownership of initial placement, parent update commits,
123
128
  identity-bearing props, events, SSR, and hydration. Local state cells batch updates into a
124
129
  microtask; eligible flat destructured primitive props join the same dependency index after React
@@ -1118,8 +1123,23 @@ Generated callback refs give directly patched host elements stable private targe
1118
1123
  React-owned component may therefore return `null`, a fragment, or multiple host nodes without
1119
1124
  shifting an unrelated compiler binding. These refs do not add attributes to SSR output.
1120
1125
 
1126
+ State-dependent `contentEditable` bindings and non-literal `contentEditable` values in host
1127
+ descriptors remain React-owned. This preserves the difference between explicit `false` (not editable)
1128
+ and an absent value (inherit from the parent). Literal strings on ordinary direct hosts remain
1129
+ eligible for compilation.
1130
+
1131
+ `title` and `meta` elements inside conditional, keyed, or recursive host descriptors remain
1132
+ React-owned. React decides their document placement and cleanup, including React 19 head placement
1133
+ and the `itemProp` exception. The compiler does not implement a separate metadata manager.
1134
+
1121
1135
  Conditional blocks have three safe ownership levels. One or more proven host-only direct branches
1122
1136
  may become compiler-owned ranges among static host siblings, including at the exact component root.
1137
+ Script elements in conditional branches or keyed rows remain React-owned, including nested and
1138
+ non-executable scripts. React retains responsibility for inert script creation on insertion and
1139
+ reinsertion; the compiler does not create these elements through its host descriptors.
1140
+ The production browser control is
1141
+ `NODE_ENV=production node packages/farm-react/scripts/test-script-ownership-browser.mjs` from the
1142
+ workspace root. Set `CHROME_PATH` to use an installed Chrome instead of Playwright's browser.
1123
1143
  A dedicated container with exactly one conditional child uses the smaller compiler-owned branch
1124
1144
  boundary. The more general React-owned conditional path accepts supported events, nested host
1125
1145
  conditionals, keyed lists, and component islands. A compiler-owned host branch may now recursively
@@ -1205,6 +1225,19 @@ When intentionally adding or changing a baseline, generate it with
1205
1225
  `pnpm --filter @farm.js/react benchmark:runtime-size` and review the byte changes before committing;
1206
1226
  do not regenerate baselines just to hide a regression. These checks do not change application output.
1207
1227
 
1228
+ Both runtime-size and keyed-target measurements compress each emitted JavaScript file independently,
1229
+ then sum the bytes. Multi-chunk builds also report per-file bytes and the union of entry chunks plus
1230
+ their static imports (`initial`), reachable dynamic imports and their dependencies (`deferred`), and
1231
+ any remaining emitted chunks (`unreferenced`). Shared chunks count once; deferred totals include all
1232
+ reachable lazy chunks, not a claim that every navigation downloads them. CSS, other assets, external
1233
+ dependencies and HTTP overhead are outside these JavaScript-only measurements. Existing single-chunk
1234
+ measurements are unchanged; concatenated code is used only for structural-marker checks.
1235
+
1236
+ Plain keyed-row features also omit conditional-boundary subscriptions, render adapters, and
1237
+ snapshot-update loops. Conditional features retain their per-block ownership and React fallback.
1238
+ The size suite checks a combined create/append/update/select/swap/remove/clear table as well as
1239
+ isolated operations, so an isolated fixture cannot hide retained conditional machinery.
1240
+
1208
1241
  Application and prototype calls, dynamic style objects, handlers outside JSX events, nested,
1209
1242
  computed, and rest props patterns, async handlers, unkeyed or index-keyed lists, unsupported map
1210
1243
  chains, unsupported conditional roots, effects, and more advanced hook support intentionally stay
package/dist/client.d.mts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from '@farm.js/core/renderer/react/client';
2
2
  export { default } from '@farm.js/core/renderer/react/client';
3
- import '@farm.js/core/renderer/react/server';
package/dist/client.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from '@farm.js/core/renderer/react/client';
2
2
  export { default } from '@farm.js/core/renderer/react/client';
3
- import '@farm.js/core/renderer/react/server';
@@ -1583,13 +1583,13 @@ function createCompilerKeyedCollectionUpdate(previous, value, kind) {
1583
1583
  return value;
1584
1584
  }
1585
1585
  var delegatedRowChangePlaceholder = () => void 0;
1586
+ var COMPILER_HMR_REGISTRY = /* @__PURE__ */ Symbol.for("@farm.js/react/compiler-hmr-registry");
1586
1587
  function getCompilerHmrRegistry() {
1587
- const registryKey = /* @__PURE__ */ Symbol.for("@farm.js/react/compiler-hmr-registry");
1588
1588
  const globalTarget = globalThis;
1589
- const existing = globalTarget[registryKey];
1589
+ const existing = globalTarget[COMPILER_HMR_REGISTRY];
1590
1590
  if (existing instanceof Map) return existing;
1591
1591
  const registry = /* @__PURE__ */ new Map();
1592
- globalTarget[registryKey] = registry;
1592
+ globalTarget[COMPILER_HMR_REGISTRY] = registry;
1593
1593
  return registry;
1594
1594
  }
1595
1595
  function renderTextValue(value) {
@@ -1731,9 +1731,6 @@ function updateAttribute(element, name, value) {
1731
1731
  if (name === "value" && (isInputElement(element) || isTextAreaElement(element))) {
1732
1732
  const nextValue = value === null || value === void 0 ? "" : String(value);
1733
1733
  if (element.value !== nextValue) element.value = nextValue;
1734
- if (value != null && isInputElement(element) && (element.type !== "number" || element.ownerDocument.activeElement !== element) && element.defaultValue !== nextValue) {
1735
- element.defaultValue = nextValue;
1736
- }
1737
1734
  return;
1738
1735
  }
1739
1736
  if (name === "value" && isSelectElement(element)) {
@@ -1757,20 +1754,8 @@ function updateAttribute(element, name, value) {
1757
1754
  } else if (value === true && !stringifiesBoolean) {
1758
1755
  element.setAttribute(attributeName, "");
1759
1756
  } else {
1760
- element.setAttribute(attributeName, compilerAttributeValue(element, name, String(value)));
1761
- }
1762
- }
1763
- var JAVASCRIPT_URL = (
1764
- // oxlint-disable-next-line no-control-regex
1765
- /^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*:/i
1766
- );
1767
- var BLOCKS_JAVASCRIPT_URLS = Number.parseInt(React__default.default.version, 10) > 18;
1768
- function compilerAttributeValue(element, name, value) {
1769
- if (!BLOCKS_JAVASCRIPT_URLS || name !== "href" && name !== "src" && name !== "action" && name !== "formAction" && name !== "data") {
1770
- return value;
1757
+ element.setAttribute(attributeName, String(value));
1771
1758
  }
1772
- const tag = element.localName;
1773
- return (name !== "data" || tag === "object") && !tag.includes("-") && JAVASCRIPT_URL.test(value) ? "javascript:throw new Error('React has blocked a javascript: URL as a security precaution.')" : value;
1774
1759
  }
1775
1760
  function createConditionalBlockComponent(owner) {
1776
1761
  class FarmConditionalBlock extends React__default.default.Component {
@@ -2550,7 +2535,7 @@ function readKeyedRowBindingValues(props, item, index) {
2550
2535
  var KEYED_ROW_TEMPLATES = /* @__PURE__ */ new WeakMap();
2551
2536
  function createKeyedRowInstance(props, document, key, item, index) {
2552
2537
  const template = props.cloneRows && KEYED_ROW_TEMPLATES.get(props);
2553
- const element = template ? template.element.cloneNode(true) : createCompilerHostElement(document, props.create(item, index));
2538
+ const element = template ? template.cloneNode(true) : createCompilerHostElement(document, props.create(item, index));
2554
2539
  const instance = {
2555
2540
  key,
2556
2541
  element,
@@ -2560,21 +2545,16 @@ function createKeyedRowInstance(props, document, key, item, index) {
2560
2545
  conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
2561
2546
  };
2562
2547
  if (props.cloneRows) {
2563
- let targets = props.targets?.(element);
2548
+ const targets = [];
2564
2549
  let found = true;
2565
- if (!targets || targets.length !== props.bindings.length || !props.bindings.every((_, index2) => targets[index2] != null)) {
2566
- targets = [];
2567
- for (const binding of props.bindings) {
2568
- const target = findCompilerHostTarget(element, binding.path);
2569
- found && (found = target !== null);
2570
- targets.push(target);
2571
- }
2550
+ for (const binding of props.bindings) {
2551
+ const target = findCompilerHostTarget(element, binding.path);
2552
+ found && (found = target !== null);
2553
+ targets.push(target);
2572
2554
  }
2573
2555
  if (found) instance.targets = targets;
2574
2556
  if (template) {
2575
2557
  for (let bindingIndex = 0; bindingIndex < targets.length; bindingIndex += 1) {
2576
- const value = instance.values[bindingIndex];
2577
- if (typeof value === "string" && value === template.classNames[bindingIndex]) continue;
2578
2558
  commitKeyedRowBinding(
2579
2559
  props.bindings[bindingIndex],
2580
2560
  instance,
@@ -2600,20 +2580,10 @@ function keyedRowTemplate(props, element, targets) {
2600
2580
  }
2601
2581
  }
2602
2582
  const template = element.cloneNode(true);
2603
- const classNames = [];
2604
- const classTargets = /* @__PURE__ */ new Set();
2605
- for (let bindingIndex = 0; bindingIndex < props.bindings.length; bindingIndex += 1) {
2606
- const binding = props.bindings[bindingIndex];
2583
+ for (const binding of props.bindings) {
2607
2584
  if (binding.kind === "text") findCompilerHostTarget(template, binding.path).textContent = "";
2608
- if (binding.kind === "attribute" && (binding.name === "className" || binding.name === "class")) {
2609
- const target = targets[bindingIndex];
2610
- if (!classTargets.has(target)) {
2611
- classNames[bindingIndex] = target.getAttribute("class") ?? void 0;
2612
- classTargets.add(target);
2613
- }
2614
- }
2615
2585
  }
2616
- return { element: template, classNames };
2586
+ return template;
2617
2587
  }
2618
2588
  function applyKeyedRowBindings(props, instance, item, index) {
2619
2589
  if (props.bindings.length < 2) {
@@ -6172,18 +6142,14 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6172
6142
  const eventTarget = event.target;
6173
6143
  if (!instance || !eventTarget) return;
6174
6144
  const capture = name.endsWith("Capture");
6175
- const descriptors = this.currentProps.events || [];
6176
- const matches = [];
6177
- for (let index = 0, length = descriptors.length; index < length; index += 1) {
6178
- if (!(index in descriptors)) continue;
6179
- const descriptor = descriptors[index];
6180
- if (descriptor.name !== name || descriptor.path === void 0) continue;
6181
- const target = findCompilerHostTarget(instance.element, descriptor.path || []);
6182
- if (target && (target === eventTarget || target.contains(eventTarget))) {
6183
- matches.push({ descriptor, target });
6184
- }
6185
- }
6186
- matches.sort(
6145
+ const matches = (this.currentProps.events || []).filter((descriptor) => descriptor.name === name && descriptor.path !== void 0).map((descriptor) => ({
6146
+ descriptor,
6147
+ target: findCompilerHostTarget(instance.element, descriptor.path || [])
6148
+ })).filter(
6149
+ (match) => Boolean(
6150
+ match.target && (match.target === eventTarget || match.target.contains(eventTarget))
6151
+ )
6152
+ ).sort(
6187
6153
  (left, right) => capture ? (left.descriptor.path?.length || 0) - (right.descriptor.path?.length || 0) : (right.descriptor.path?.length || 0) - (left.descriptor.path?.length || 0)
6188
6154
  );
6189
6155
  for (const match of matches) {
@@ -6687,24 +6653,22 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6687
6653
  } else {
6688
6654
  applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6689
6655
  }
6690
- if (options.conditionals) {
6691
- const conditionalValues = this.readConditionalValues(
6692
- this.currentProps,
6693
- rows.items[index],
6694
- index
6695
- );
6696
- for (const [id, values] of conditionalValues) {
6697
- if (options.conditionals.changed(existing.conditionalValues.get(id), values)) {
6698
- conditionalChanges.push({
6699
- key,
6700
- id,
6701
- item: rows.items[index],
6702
- index
6703
- });
6704
- }
6656
+ const conditionalValues = this.readConditionalValues(
6657
+ this.currentProps,
6658
+ rows.items[index],
6659
+ index
6660
+ );
6661
+ for (const [id, values] of conditionalValues) {
6662
+ if (options.conditionals?.changed(existing.conditionalValues.get(id), values)) {
6663
+ conditionalChanges.push({
6664
+ key,
6665
+ id,
6666
+ item: rows.items[index],
6667
+ index
6668
+ });
6705
6669
  }
6706
- existing.conditionalValues = conditionalValues;
6707
6670
  }
6671
+ existing.conditionalValues = conditionalValues;
6708
6672
  existing.item = rows.items[index];
6709
6673
  existing.index = index;
6710
6674
  }
@@ -6909,12 +6873,10 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6909
6873
  let oldIndex = 0;
6910
6874
  for (const key of this.instances.keys()) oldIndices.set(key, oldIndex++);
6911
6875
  }
6912
- if (hasSurvivingRows || options.hostBlocks) {
6913
- for (const [key, instance] of this.instances) {
6914
- if (!nextKeys.has(key)) {
6915
- instance.scope?.cleanup();
6916
- if (hasSurvivingRows) instance.element.remove();
6917
- }
6876
+ for (const [key, instance] of this.instances) {
6877
+ if (!nextKeys.has(key)) {
6878
+ instance.scope?.cleanup();
6879
+ if (hasSurvivingRows) instance.element.remove();
6918
6880
  }
6919
6881
  }
6920
6882
  const sequence = hasSurvivingRows ? rows.keys.map((key) => oldIndices.get(key) ?? -1) : [];
@@ -7637,14 +7599,6 @@ var keyedRowsPositionHintedRuntimeFeature = {
7637
7599
  })
7638
7600
  })
7639
7601
  };
7640
- var keyedRowsPlainPositionHintedRuntimeFeature = {
7641
- name: "keyed-rows:plain-position-hinted",
7642
- create: (owner) => ({
7643
- KeyedRows: createKeyedRowsBlockComponentCore(owner, {
7644
- keyedUpdates: keyedPositionUpdateRuntime
7645
- })
7646
- })
7647
- };
7648
7602
  var keyedRowsBatchPositionHintedRuntimeFeature = {
7649
7603
  name: "keyed-rows:batch-position-hinted",
7650
7604
  create: (owner) => ({
@@ -7669,22 +7623,6 @@ var keyedRowsReorderHintedRuntimeFeature = {
7669
7623
  })
7670
7624
  })
7671
7625
  };
7672
- var keyedRowsPlainReorderHintedRuntimeFeature = {
7673
- name: "keyed-rows:plain-reorder-hinted",
7674
- create: (owner) => ({
7675
- KeyedRows: createKeyedRowsBlockComponentCore(owner, {
7676
- keyedUpdates: keyedReorderUpdateRuntime
7677
- })
7678
- })
7679
- };
7680
- var keyedRowsPlainMapReorderHintedRuntimeFeature = {
7681
- name: "keyed-rows:plain-map-reorder-hinted",
7682
- create: (owner) => ({
7683
- KeyedRows: createKeyedRowsBlockComponentCore(owner, {
7684
- keyedUpdates: keyedMapReorderUpdateRuntime
7685
- })
7686
- })
7687
- };
7688
7626
  var keyedRowsMapReorderHintedRuntimeFeature = {
7689
7627
  name: "keyed-rows:map-reorder-hinted",
7690
7628
  create: (owner) => ({
@@ -8369,26 +8307,6 @@ function createCompiledComponentWithFeatures(definition, runtimeFeatures) {
8369
8307
  current: definition
8370
8308
  };
8371
8309
  const refreshListeners = /* @__PURE__ */ new Set();
8372
- const component = createCompiledComponentRuntime(
8373
- definitionReference,
8374
- runtimeFeatures,
8375
- refreshListeners
8376
- );
8377
- if (definition.hmrId) {
8378
- getCompilerHmrRegistry().set(definition.hmrId, {
8379
- component,
8380
- definition: definitionReference,
8381
- refreshListeners,
8382
- stateSignature,
8383
- runtimeSignature
8384
- });
8385
- }
8386
- return component;
8387
- }
8388
- function createCompiledComponentWithoutRefresh(definition, runtimeFeatures) {
8389
- return createCompiledComponentRuntime({ current: definition }, runtimeFeatures);
8390
- }
8391
- function createCompiledComponentRuntime(definitionReference, runtimeFeatures, refreshListeners) {
8392
8310
  class FarmCompiledComponent extends React__default.default.Component {
8393
8311
  constructor(props) {
8394
8312
  super(props);
@@ -8699,7 +8617,7 @@ function createCompiledComponentRuntime(definitionReference, runtimeFeatures, re
8699
8617
  }
8700
8618
  componentDidMount() {
8701
8619
  this.mounted = true;
8702
- refreshListeners?.add(this.refreshDefinition);
8620
+ refreshListeners.add(this.refreshDefinition);
8703
8621
  this.componentDidUpdate();
8704
8622
  }
8705
8623
  getSnapshotBeforeUpdate() {
@@ -8755,7 +8673,7 @@ function createCompiledComponentRuntime(definitionReference, runtimeFeatures, re
8755
8673
  this.bindingValues.clear();
8756
8674
  this.activeBinding = null;
8757
8675
  this.activeDependencies = null;
8758
- refreshListeners?.delete(this.refreshDefinition);
8676
+ refreshListeners.delete(this.refreshDefinition);
8759
8677
  }
8760
8678
  render() {
8761
8679
  if (this.hasBindingError) throw this.bindingError;
@@ -8797,8 +8715,18 @@ function createCompiledComponentRuntime(definitionReference, runtimeFeatures, re
8797
8715
  return renderedElement;
8798
8716
  }
8799
8717
  }
8800
- FarmCompiledComponent.displayName = `FarmCompiled(${definitionReference.current.displayName})`;
8801
- return FarmCompiledComponent;
8718
+ FarmCompiledComponent.displayName = `FarmCompiled(${definition.displayName})`;
8719
+ const component = FarmCompiledComponent;
8720
+ if (definition.hmrId) {
8721
+ getCompilerHmrRegistry().set(definition.hmrId, {
8722
+ component,
8723
+ definition: definitionReference,
8724
+ refreshListeners,
8725
+ stateSignature,
8726
+ runtimeSignature
8727
+ });
8728
+ }
8729
+ return component;
8802
8730
  }
8803
8731
  var COMPLETE_RUNTIME_FEATURES = [
8804
8732
  conditionalRuntimeFeature,
@@ -8820,7 +8748,6 @@ exports.conditionalRangesRuntimeFeature = conditionalRangesRuntimeFeature;
8820
8748
  exports.conditionalRuntimeFeature = conditionalRuntimeFeature;
8821
8749
  exports.createCompiledComponent = createCompiledComponent;
8822
8750
  exports.createCompiledComponentWithFeatures = createCompiledComponentWithFeatures;
8823
- exports.createCompiledComponentWithoutRefresh = createCompiledComponentWithoutRefresh;
8824
8751
  exports.createCompilerKeyedArrayAppend = createCompilerKeyedArrayAppend;
8825
8752
  exports.createCompilerKeyedArrayBatchInsert = createCompilerKeyedArrayBatchInsert;
8826
8753
  exports.createCompilerKeyedArrayFilter = createCompilerKeyedArrayFilter;
@@ -8920,9 +8847,6 @@ exports.keyedRowsMapLookupRuntimeFeature = keyedRowsMapLookupRuntimeFeature;
8920
8847
  exports.keyedRowsMapReorderHintedRuntimeFeature = keyedRowsMapReorderHintedRuntimeFeature;
8921
8848
  exports.keyedRowsMappedRollingWindowHintedRuntimeFeature = keyedRowsMappedRollingWindowHintedRuntimeFeature;
8922
8849
  exports.keyedRowsMembershipRuntimeFeature = keyedRowsMembershipRuntimeFeature;
8923
- exports.keyedRowsPlainMapReorderHintedRuntimeFeature = keyedRowsPlainMapReorderHintedRuntimeFeature;
8924
- exports.keyedRowsPlainPositionHintedRuntimeFeature = keyedRowsPlainPositionHintedRuntimeFeature;
8925
- exports.keyedRowsPlainReorderHintedRuntimeFeature = keyedRowsPlainReorderHintedRuntimeFeature;
8926
8850
  exports.keyedRowsPlainRuntimeFeature = keyedRowsPlainRuntimeFeature;
8927
8851
  exports.keyedRowsPositionHintedRuntimeFeature = keyedRowsPositionHintedRuntimeFeature;
8928
8852
  exports.keyedRowsPrependHintedRuntimeFeature = keyedRowsPrependHintedRuntimeFeature;