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

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,18 @@ 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
+ `title` and `meta` elements inside conditional, keyed, or recursive host descriptors remain
1127
+ React-owned. React decides their document placement and cleanup, including React 19 head placement
1128
+ and the `itemProp` exception. The compiler does not implement a separate metadata manager.
1129
+
1121
1130
  Conditional blocks have three safe ownership levels. One or more proven host-only direct branches
1122
1131
  may become compiler-owned ranges among static host siblings, including at the exact component root.
1132
+ Script elements in conditional branches or keyed rows remain React-owned, including nested and
1133
+ non-executable scripts. React retains responsibility for inert script creation on insertion and
1134
+ reinsertion; the compiler does not create these elements through its host descriptors.
1135
+ The production browser control is
1136
+ `NODE_ENV=production node packages/farm-react/scripts/test-script-ownership-browser.mjs` from the
1137
+ workspace root. Set `CHROME_PATH` to use an installed Chrome instead of Playwright's browser.
1123
1138
  A dedicated container with exactly one conditional child uses the smaller compiler-owned branch
1124
1139
  boundary. The more general React-owned conditional path accepts supported events, nested host
1125
1140
  conditionals, keyed lists, and component islands. A compiler-owned host branch may now recursively
@@ -1205,6 +1220,19 @@ When intentionally adding or changing a baseline, generate it with
1205
1220
  `pnpm --filter @farm.js/react benchmark:runtime-size` and review the byte changes before committing;
1206
1221
  do not regenerate baselines just to hide a regression. These checks do not change application output.
1207
1222
 
1223
+ Both runtime-size and keyed-target measurements compress each emitted JavaScript file independently,
1224
+ then sum the bytes. Multi-chunk builds also report per-file bytes and the union of entry chunks plus
1225
+ their static imports (`initial`), reachable dynamic imports and their dependencies (`deferred`), and
1226
+ any remaining emitted chunks (`unreferenced`). Shared chunks count once; deferred totals include all
1227
+ reachable lazy chunks, not a claim that every navigation downloads them. CSS, other assets, external
1228
+ dependencies and HTTP overhead are outside these JavaScript-only measurements. Existing single-chunk
1229
+ measurements are unchanged; concatenated code is used only for structural-marker checks.
1230
+
1231
+ Plain keyed-row features also omit conditional-boundary subscriptions, render adapters, and
1232
+ snapshot-update loops. Conditional features retain their per-block ownership and React fallback.
1233
+ The size suite checks a combined create/append/update/select/swap/remove/clear table as well as
1234
+ isolated operations, so an isolated fixture cannot hide retained conditional machinery.
1235
+
1208
1236
  Application and prototype calls, dynamic style objects, handlers outside JSX events, nested,
1209
1237
  computed, and rest props patterns, async handlers, unkeyed or index-keyed lists, unsupported map
1210
1238
  chains, unsupported conditional roots, effects, and more advanced hook support intentionally stay
@@ -4603,13 +4603,7 @@ function reconcileCompilerKeyedMapUpdate(props, dirtyState, collectionToken, ins
4603
4603
  }
4604
4604
  }
4605
4605
  applyKeyedRowBindings(props, instance, item, index);
4606
- const conditionalValues = conditionals?.readValues(props, item, index) || EMPTY_KEYED_ROW_CONDITIONAL_VALUES;
4607
- for (const [id, values] of conditionalValues) {
4608
- if (conditionals?.changed(instance.conditionalValues.get(id), values)) {
4609
- conditionalChanges.push({ key, id, item, index });
4610
- }
4611
- }
4612
- instance.conditionalValues = conditionalValues;
4606
+ conditionals?.refresh(props, instance, key, item, index, conditionalChanges);
4613
4607
  instance.item = item;
4614
4608
  }
4615
4609
  return {
@@ -6024,6 +6018,7 @@ function reconcileCompilerKeyedArrayFilter(props, dirtyState, collectionToken, i
6024
6018
  for (const instance of instances.values()) instance.index = index++;
6025
6019
  return instances;
6026
6020
  }
6021
+ var renderKeyedRowConditional = (item, index, _id, render) => render(item, index);
6027
6022
  function createKeyedRowConditionalRuntime() {
6028
6023
  class FarmKeyedRowConditional extends React__default.default.Component {
6029
6024
  constructor() {
@@ -6066,30 +6061,48 @@ function createKeyedRowConditionalRuntime() {
6066
6061
  }
6067
6062
  }
6068
6063
  FarmKeyedRowConditional.displayName = "FarmCompiledKeyedRowConditional";
6069
- return {
6070
- element: (props) => React__default.default.createElement(FarmKeyedRowConditional, {
6071
- key: `${props.rowKey}:${props.id}`,
6072
- ...props
6073
- }),
6074
- readValues: readKeyedRowConditionalValues,
6075
- changed: keyedRowConditionalChanged,
6076
- owner: (listeners) => ({
6077
- subscribe(key, id, refresh) {
6078
- let row = listeners.get(key);
6079
- if (!row) {
6080
- row = /* @__PURE__ */ new Map();
6081
- listeners.set(key, row);
6064
+ class ConditionalBlock {
6065
+ constructor(context) {
6066
+ this.context = context;
6067
+ this.listeners = /* @__PURE__ */ new Map();
6068
+ this.owner = {
6069
+ subscribe: (key, id, refresh) => {
6070
+ let row = this.listeners.get(key);
6071
+ if (!row) {
6072
+ row = /* @__PURE__ */ new Map();
6073
+ this.listeners.set(key, row);
6074
+ }
6075
+ row.set(id, refresh);
6076
+ return () => {
6077
+ const current = this.listeners.get(key);
6078
+ if (current?.get(id) !== refresh) return;
6079
+ current.delete(id);
6080
+ if (current.size === 0) this.listeners.delete(key);
6081
+ };
6082
6082
  }
6083
- row.set(id, refresh);
6084
- return () => {
6085
- const current = listeners.get(key);
6086
- if (current?.get(id) !== refresh) return;
6087
- current.delete(id);
6088
- if (current.size === 0) listeners.delete(key);
6089
- };
6083
+ };
6084
+ this.render = (item, index, id, render) => {
6085
+ if (this.context.state.fallback) return render(item, index);
6086
+ const rowKey = keyedRowIdentity(this.context.currentProps.rowKey(item, index));
6087
+ return React__default.default.createElement(FarmKeyedRowConditional, {
6088
+ key: `${rowKey}:${id}`,
6089
+ owner: this.owner,
6090
+ rowKey,
6091
+ id,
6092
+ renderVersion: this.context.renderVersion,
6093
+ item,
6094
+ index,
6095
+ render
6096
+ });
6097
+ };
6098
+ }
6099
+ prune(instances) {
6100
+ if (this.listeners.size === 0) return;
6101
+ for (const key of this.listeners.keys()) {
6102
+ if (!instances.has(key)) this.listeners.delete(key);
6090
6103
  }
6091
- }),
6092
- notify(listeners, changes, afterCommit) {
6104
+ }
6105
+ notify(changes, afterCommit) {
6093
6106
  let pending = changes.length;
6094
6107
  const committed = () => {
6095
6108
  pending -= 1;
@@ -6097,12 +6110,25 @@ function createKeyedRowConditionalRuntime() {
6097
6110
  };
6098
6111
  reactDom.flushSync(() => {
6099
6112
  for (const change of changes) {
6100
- const refresh = listeners.get(change.key)?.get(change.id);
6113
+ const refresh = this.listeners.get(change.key)?.get(change.id);
6101
6114
  if (refresh) refresh(change.item, change.index, committed);
6102
6115
  else committed();
6103
6116
  }
6104
6117
  });
6105
6118
  }
6119
+ }
6120
+ return {
6121
+ create: (context) => new ConditionalBlock(context),
6122
+ readValues: readKeyedRowConditionalValues,
6123
+ refresh(props, instance, key, item, index, changes) {
6124
+ const values = readKeyedRowConditionalValues(props, item, index);
6125
+ for (const [id, next] of values) {
6126
+ if (keyedRowConditionalChanged(instance.conditionalValues.get(id), next)) {
6127
+ changes.push({ key, id, item, index });
6128
+ }
6129
+ }
6130
+ instance.conditionalValues = values;
6131
+ }
6106
6132
  };
6107
6133
  }
6108
6134
  function createKeyedRowHostRuntime() {
@@ -6132,11 +6158,10 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6132
6158
  this.keyedTargets = options.keyedTargets?.(this.props);
6133
6159
  this.renderVersion = 0;
6134
6160
  this.eventHandlers = /* @__PURE__ */ new Map();
6135
- this.conditionalListeners = /* @__PURE__ */ new Map();
6161
+ this.conditionals = options.conditionals?.create(this);
6136
6162
  this.instancesByElement = /* @__PURE__ */ new WeakMap();
6137
6163
  // False after a rebuild without delegated events left surviving rows unindexed.
6138
6164
  this.elementIndexComplete = true;
6139
- this.conditionalOwner = options.conditionals?.owner(this.conditionalListeners);
6140
6165
  this.captureRoot = (root) => {
6141
6166
  this.root = root;
6142
6167
  };
@@ -6191,18 +6216,6 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6191
6216
  if (event.isPropagationStopped()) break;
6192
6217
  }
6193
6218
  };
6194
- this.rowConditional = (item, index, conditionalId, render) => {
6195
- if (this.state.fallback || !options.conditionals) return render(item, index);
6196
- return options.conditionals.element({
6197
- owner: this.conditionalOwner,
6198
- rowKey: keyedRowIdentity(this.currentProps.rowKey(item, index)),
6199
- id: conditionalId,
6200
- renderVersion: this.renderVersion,
6201
- item,
6202
- index,
6203
- render
6204
- });
6205
- };
6206
6219
  this.refresh = (afterCommit, dirtyState) => {
6207
6220
  if (dirtyState && options.keyedUpdates && this.mounted && this.root && !this.state.fallback) {
6208
6221
  const result = options.keyedUpdates.reconcile(
@@ -6256,7 +6269,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6256
6269
  this.instances = positionedInstances;
6257
6270
  this.rebuildElementIndex(this.instances);
6258
6271
  this.pruneEventHandlers();
6259
- this.pruneConditionalListeners();
6272
+ this.conditionals?.prune(this.instances);
6260
6273
  }
6261
6274
  this.commitCurrentCollection(dirtyState);
6262
6275
  afterCommit?.();
@@ -6276,7 +6289,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6276
6289
  if (removedRows) {
6277
6290
  this.rebuildElementIndex(this.instances);
6278
6291
  this.pruneEventHandlers();
6279
- this.pruneConditionalListeners();
6292
+ this.conditionals?.prune(this.instances);
6280
6293
  }
6281
6294
  this.commitCurrentCollection(dirtyState);
6282
6295
  afterCommit?.();
@@ -6302,12 +6315,12 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6302
6315
  }
6303
6316
  for (const key of delta.removedKeys) {
6304
6317
  this.eventHandlers.delete(key);
6305
- this.conditionalListeners.delete(key);
6318
+ this.conditionals?.listeners.delete(key);
6306
6319
  }
6307
6320
  } else {
6308
6321
  this.rebuildElementIndex(this.instances);
6309
6322
  this.pruneEventHandlers();
6310
- this.pruneConditionalListeners();
6323
+ this.conditionals?.prune(this.instances);
6311
6324
  }
6312
6325
  this.commitCurrentCollection(dirtyState);
6313
6326
  afterCommit?.();
@@ -6324,7 +6337,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6324
6337
  this.instances = filteredInstances;
6325
6338
  if (!this.elementIndexComplete) this.rebuildElementIndex(this.instances);
6326
6339
  this.pruneEventHandlers();
6327
- this.pruneConditionalListeners();
6340
+ this.conditionals?.prune(this.instances);
6328
6341
  this.commitCurrentCollection(dirtyState);
6329
6342
  afterCommit?.();
6330
6343
  return;
@@ -6473,12 +6486,6 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6473
6486
  if (!this.instances.has(key)) this.eventHandlers.delete(key);
6474
6487
  }
6475
6488
  }
6476
- pruneConditionalListeners() {
6477
- if (this.conditionalListeners.size === 0) return;
6478
- for (const key of this.conditionalListeners.keys()) {
6479
- if (!this.instances.has(key)) this.conditionalListeners.delete(key);
6480
- }
6481
- }
6482
6489
  commitCurrentCollection(dirtyState) {
6483
6490
  this.collectionToken = options.keyedUpdates?.commit(
6484
6491
  this.currentProps.items(),
@@ -6533,7 +6540,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6533
6540
  this.reactElements = elements;
6534
6541
  this.rebuildElementIndex(instances);
6535
6542
  this.pruneEventHandlers();
6536
- this.pruneConditionalListeners();
6543
+ this.conditionals?.prune(this.instances);
6537
6544
  this.commitCurrentCollection();
6538
6545
  return true;
6539
6546
  }
@@ -6570,7 +6577,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6570
6577
  }
6571
6578
  notifyConditionalChanges(changes, afterCommit) {
6572
6579
  if (changes.length === 0) afterCommit?.();
6573
- else options.conditionals.notify(this.conditionalListeners, changes, afterCommit);
6580
+ else this.conditionals.notify(changes, afterCommit);
6574
6581
  }
6575
6582
  refreshDirtyBindings(dirtyState, afterCommit) {
6576
6583
  if (!this.mounted || !this.root || this.state.fallback || this.hasReactOwnedRows() || this.currentProps.hostBlocks || !this.currentProps.structureDependencies || this.currentProps.structureDependencies.some((dependency) => dirtyState.has(dependency)) || this.currentProps.bindings.some((binding) => binding.dependencies === void 0)) {
@@ -6687,24 +6694,14 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6687
6694
  } else {
6688
6695
  applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6689
6696
  }
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
- }
6705
- }
6706
- existing.conditionalValues = conditionalValues;
6707
- }
6697
+ options.conditionals?.refresh(
6698
+ this.currentProps,
6699
+ existing,
6700
+ key,
6701
+ rows.items[index],
6702
+ index,
6703
+ conditionalChanges
6704
+ );
6708
6705
  existing.item = rows.items[index];
6709
6706
  existing.index = index;
6710
6707
  }
@@ -6811,22 +6808,14 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6811
6808
  } else {
6812
6809
  applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6813
6810
  }
6814
- const conditionalValues = this.readConditionalValues(
6811
+ options.conditionals?.refresh(
6815
6812
  this.currentProps,
6813
+ existing,
6814
+ key,
6816
6815
  rows.items[index],
6817
- index
6816
+ index,
6817
+ conditionalChanges
6818
6818
  );
6819
- for (const [id, values] of conditionalValues) {
6820
- if (options.conditionals?.changed(existing.conditionalValues.get(id), values)) {
6821
- conditionalChanges.push({
6822
- key,
6823
- id,
6824
- item: rows.items[index],
6825
- index
6826
- });
6827
- }
6828
- }
6829
- existing.conditionalValues = conditionalValues;
6830
6819
  existing.item = rows.items[index];
6831
6820
  existing.index = index;
6832
6821
  }
@@ -6835,7 +6824,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6835
6824
  instance.element.remove();
6836
6825
  this.instances.delete(instance.key);
6837
6826
  this.eventHandlers.delete(instance.key);
6838
- this.conditionalListeners.delete(instance.key);
6827
+ this.conditionals?.listeners.delete(instance.key);
6839
6828
  }
6840
6829
  this.commitCurrentCollection(dirtyState);
6841
6830
  this.notifyConditionalChanges(conditionalChanges, afterCommit);
@@ -6876,7 +6865,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6876
6865
  this.instancesByElement = /* @__PURE__ */ new WeakMap();
6877
6866
  this.elementIndexComplete = true;
6878
6867
  this.eventHandlers.clear();
6879
- this.conditionalListeners.clear();
6868
+ this.conditionals?.listeners.clear();
6880
6869
  this.commitCurrentCollection(dirtyState);
6881
6870
  afterCommit?.();
6882
6871
  return;
@@ -6940,22 +6929,14 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6940
6929
  } else {
6941
6930
  applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6942
6931
  }
6943
- const conditionalValues = this.readConditionalValues(
6932
+ options.conditionals?.refresh(
6944
6933
  this.currentProps,
6934
+ existing,
6935
+ key,
6945
6936
  rows.items[index],
6946
- index
6937
+ index,
6938
+ conditionalChanges
6947
6939
  );
6948
- for (const [id, values] of conditionalValues) {
6949
- if (options.conditionals?.changed(existing.conditionalValues.get(id), values)) {
6950
- conditionalChanges.push({
6951
- key,
6952
- id,
6953
- item: rows.items[index],
6954
- index
6955
- });
6956
- }
6957
- }
6958
- existing.conditionalValues = conditionalValues;
6959
6940
  existing.item = rows.items[index];
6960
6941
  existing.index = index;
6961
6942
  nextInstances.push(existing);
@@ -7018,7 +6999,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
7018
6999
  this.rebuildElementIndex(this.instances);
7019
7000
  }
7020
7001
  this.pruneEventHandlers();
7021
- this.pruneConditionalListeners();
7002
+ this.conditionals?.prune(this.instances);
7022
7003
  this.commitCurrentCollection(dirtyState);
7023
7004
  this.notifyConditionalChanges(conditionalChanges, afterCommit);
7024
7005
  }
@@ -7091,11 +7072,14 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
7091
7072
  this.instancesByElement = /* @__PURE__ */ new WeakMap();
7092
7073
  this.elementIndexComplete = true;
7093
7074
  this.eventHandlers.clear();
7094
- this.conditionalListeners.clear();
7075
+ this.conditionals?.listeners.clear();
7095
7076
  }
7096
7077
  render() {
7097
7078
  this.renderVersion += 1;
7098
- const container = this.currentProps.render(this.rowEvent, this.rowConditional);
7079
+ const container = this.currentProps.render(
7080
+ this.rowEvent,
7081
+ this.conditionals?.render || renderKeyedRowConditional
7082
+ );
7099
7083
  if (!React__default.default.isValidElement(container) || typeof container.type !== "string") {
7100
7084
  throw new TypeError(
7101
7085
  `Compiled keyed rows ${this.currentProps.id} must own one host container.`