@jqhtml/core 2.3.50 → 2.3.54

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/dist/index.cjs CHANGED
@@ -500,6 +500,70 @@ function register(source) {
500
500
  'class name mangling, define static component_name or use register_component().');
501
501
  }
502
502
 
503
+ /**
504
+ * JQHTML Runtime Configuration
505
+ *
506
+ * Integration-level settings supplied by the host application (RSpade, Laravel,
507
+ * a bundler entry point) when jqhtml is loaded. Distinct from `jqhtml.debug`,
508
+ * which is a developer's interactive tracing switch: config here describes the
509
+ * ENVIRONMENT the app is running in, and jqhtml derives behaviour from it.
510
+ *
511
+ * jqhtml.init($, { mode: 'production' });
512
+ * jqhtml.configure({ mode: 'development' });
513
+ *
514
+ * Default mode is 'development', so an integration that passes nothing keeps
515
+ * every diagnostic. Production is always opt-in.
516
+ */
517
+ /** Flags implied by each mode. Add future conventions here, not at call sites. */
518
+ const MODE_DEFAULTS = {
519
+ development: {
520
+ warn_uncacheable_args: true,
521
+ debug_attributes: true,
522
+ },
523
+ production: {
524
+ warn_uncacheable_args: false,
525
+ debug_attributes: false,
526
+ },
527
+ };
528
+ let _mode = 'development';
529
+ let _flags = { ...MODE_DEFAULTS.development };
530
+ /**
531
+ * Apply integration configuration.
532
+ *
533
+ * `mode` resets every flag to that mode's defaults; any explicit flag in the
534
+ * same call then overrides it. Calling with only flags leaves the mode alone.
535
+ * Repeated calls merge.
536
+ */
537
+ function configure(config) {
538
+ if (!config)
539
+ return;
540
+ if (config.mode) {
541
+ if (!MODE_DEFAULTS[config.mode]) {
542
+ throw new Error(`[JQHTML] Unknown mode '${config.mode}'. Expected 'development' or 'production'.`);
543
+ }
544
+ _mode = config.mode;
545
+ _flags = { ...MODE_DEFAULTS[config.mode] };
546
+ }
547
+ if (config.warn_uncacheable_args !== undefined) {
548
+ _flags.warn_uncacheable_args = !!config.warn_uncacheable_args;
549
+ }
550
+ if (config.debug_attributes !== undefined) {
551
+ _flags.debug_attributes = !!config.debug_attributes;
552
+ }
553
+ }
554
+ /** Current mode plus every resolved flag. */
555
+ function get_config() {
556
+ return { mode: _mode, ..._flags };
557
+ }
558
+ /** True when debug-only DOM attributes (data-sid) should be emitted. */
559
+ function debug_attributes_enabled() {
560
+ return _flags.debug_attributes;
561
+ }
562
+ /** True when uncacheable-args warnings should be printed. */
563
+ function warn_uncacheable_args_enabled() {
564
+ return _flags.warn_uncacheable_args;
565
+ }
566
+
503
567
  /**
504
568
  * JQHTML v2 Instruction Processor
505
569
  *
@@ -637,6 +701,9 @@ function process_tag_to_html(instruction, html, tagElements, components, context
637
701
  }
638
702
  // Add simple string/numeric attributes directly
639
703
  for (const [key, value] of Object.entries(attrs)) {
704
+ if (key === 'data-sid' && !debug_attributes_enabled()) {
705
+ continue; // debug-only attribute; the scoped id is what $sid() resolves
706
+ }
640
707
  if (!key.startsWith('$') && !key.startsWith('on') && !key.startsWith('@') &&
641
708
  !key.startsWith('data-bind-') && !key.startsWith('data-__-on-') &&
642
709
  (typeof value === 'string' || typeof value === 'number')) {
@@ -726,7 +793,10 @@ function process_component_to_html(instruction, html, components, context) {
726
793
  const baseId = props['data-sid'];
727
794
  // The compiled code ALWAYS sets props['id'] with the correct scoped value
728
795
  // Just use it directly - it already has the correct parent _cid baked in
729
- html.push(` id="${props['id']}" data-sid="${baseId}"`);
796
+ // data-sid is debug-only: $sid() resolves via the scoped id, never this.
797
+ html.push(debug_attributes_enabled()
798
+ ? ` id="${props['id']}" data-sid="${baseId}"`
799
+ : ` id="${props['id']}"`);
730
800
  }
731
801
  // Regular id passes through unchanged
732
802
  else if (props['id']) {
@@ -868,6 +938,10 @@ function apply_attributes(element, attrs, context) {
868
938
  }
869
939
  }
870
940
  else if (key.startsWith('data-')) {
941
+ // data-sid is debug-only - suppressed entirely in production
942
+ if (key === 'data-sid' && !debug_attributes_enabled()) {
943
+ continue;
944
+ }
871
945
  // Data attributes - go into DOM
872
946
  const attrValue = typeof value === "string" ? value.trim() : value;
873
947
  element.attr(key, attrValue);
@@ -1230,6 +1304,146 @@ function handleComponentError(component, phase, error) {
1230
1304
  // 9. Performance Budgets - Warn when components exceed size/time limits
1231
1305
  // 10. Accessibility Auditing - Check for missing ARIA attributes
1232
1306
 
1307
+ /**
1308
+ * JQHTML Cache Key Serializer
1309
+ *
1310
+ * Produces a deterministic string for a plain-data argument value, so that two
1311
+ * structurally equal objects built on separate renders yield the SAME cache key.
1312
+ * Templates rebuild `{contact_id: 12}` on every render, so identity-based keying
1313
+ * can never match and permanently opts the receiving component out of caching.
1314
+ *
1315
+ * ---------------------------------------------------------------------------
1316
+ * THIS IS NOT `process_for_serialization()` IN local-storage.ts. DO NOT MERGE THEM.
1317
+ *
1318
+ * That serializer stores cache VALUES and deliberately degrades: a function, a
1319
+ * symbol or a circular reference is dropped and serialization continues, because
1320
+ * losing a method while keeping the data is the right trade for a payload.
1321
+ *
1322
+ * For a cache KEY that policy manufactures false hits. Two argument objects that
1323
+ * differ ONLY by a callback would serialize identically, and a component would
1324
+ * render with another component's cached content - strictly worse than not
1325
+ * caching at all. So this serializer DECLINES on the first value it cannot
1326
+ * express exactly. It never drops anything.
1327
+ * ---------------------------------------------------------------------------
1328
+ *
1329
+ * Allow-list, and nothing else: null, undefined, boolean, number, string, Date,
1330
+ * arrays, and plain objects (prototype Object.prototype or null), in any nesting.
1331
+ * Everything else declines with a reason that reaches `data-nocache`.
1332
+ */
1333
+ /**
1334
+ * Values larger than this are declined rather than keyed. The supported case is a
1335
+ * handful of key/value pairs or a list of ids - not a payload. Declining loudly
1336
+ * beats spending the budget on a key nobody benefits from.
1337
+ */
1338
+ const MAX_KEY_BYTES = 500;
1339
+ class Decline extends Error {
1340
+ constructor(reason) {
1341
+ super(reason);
1342
+ this.reason = reason;
1343
+ }
1344
+ }
1345
+ function push(state, text) {
1346
+ state.size += text.length;
1347
+ if (state.size > MAX_KEY_BYTES) {
1348
+ throw new Decline('too-large');
1349
+ }
1350
+ return text;
1351
+ }
1352
+ /**
1353
+ * Length-prefix strings so that no combination of separators can make two
1354
+ * different structures produce the same text.
1355
+ */
1356
+ function encode_string(state, prefix, value) {
1357
+ return push(state, `${prefix}${value.length}:${value}`);
1358
+ }
1359
+ function walk(value, state) {
1360
+ // --- primitives, each tagged so shapes cannot collide ---
1361
+ if (value === null)
1362
+ return push(state, 'n');
1363
+ if (value === undefined)
1364
+ return push(state, 'u');
1365
+ const type = typeof value;
1366
+ if (type === 'boolean')
1367
+ return push(state, value ? 'b1' : 'b0');
1368
+ if (type === 'number')
1369
+ return push(state, `d${String(value)}`);
1370
+ if (type === 'string')
1371
+ return encode_string(state, 's', value);
1372
+ if (type === 'function')
1373
+ throw new Decline('function');
1374
+ if (type === 'symbol')
1375
+ throw new Decline('symbol');
1376
+ if (type === 'bigint')
1377
+ throw new Decline('bigint');
1378
+ if (type !== 'object')
1379
+ throw new Decline(type);
1380
+ // --- objects: reject the impostors before treating anything as data ---
1381
+ if (typeof value.nodeType === 'number')
1382
+ throw new Decline('dom-node');
1383
+ if (value.jquery)
1384
+ throw new Decline('jquery');
1385
+ if (state.seen.has(value))
1386
+ throw new Decline('circular');
1387
+ state.seen.add(value);
1388
+ try {
1389
+ if (value instanceof Date) {
1390
+ const time = value.getTime();
1391
+ if (Number.isNaN(time))
1392
+ throw new Decline('invalid-date');
1393
+ return push(state, `t${value.toISOString()}`);
1394
+ }
1395
+ if (Array.isArray(value)) {
1396
+ // Order is meaningful - never sorted.
1397
+ const parts = [];
1398
+ push(state, 'a[');
1399
+ for (let i = 0; i < value.length; i++) {
1400
+ parts.push(walk(value[i], state));
1401
+ }
1402
+ push(state, ']');
1403
+ return `a[${parts.join(',')}]`;
1404
+ }
1405
+ // Plain object ONLY. A class instance, Map, Set, RegExp, Error, etc. is
1406
+ // declined: two different classes with identical fields would otherwise
1407
+ // serialize the same and collide.
1408
+ const proto = Object.getPrototypeOf(value);
1409
+ if (proto !== Object.prototype && proto !== null) {
1410
+ throw new Decline('non-plain-object');
1411
+ }
1412
+ // Recursive key sort - the existing top-level sort is not enough for nesting.
1413
+ const keys = Object.keys(value).sort();
1414
+ const parts = [];
1415
+ push(state, 'o{');
1416
+ for (const key of keys) {
1417
+ const encoded_key = encode_string(state, 'k', key);
1418
+ parts.push(`${encoded_key}=${walk(value[key], state)}`);
1419
+ }
1420
+ push(state, '}');
1421
+ return `o{${parts.join(',')}}`;
1422
+ }
1423
+ finally {
1424
+ state.seen.delete(value);
1425
+ }
1426
+ }
1427
+ /**
1428
+ * Serialize a value for use in a cache key.
1429
+ *
1430
+ * @returns `{ok: true, text}` when the value is exactly expressible, or
1431
+ * `{ok: false, reason}` naming why it is not. Never throws.
1432
+ */
1433
+ function serialize_for_cache_key(value) {
1434
+ const state = { seen: new WeakSet(), size: 0 };
1435
+ try {
1436
+ return { ok: true, text: walk(value, state) };
1437
+ }
1438
+ catch (error) {
1439
+ if (error instanceof Decline) {
1440
+ return { ok: false, reason: error.reason };
1441
+ }
1442
+ // A throwing getter or exotic proxy trap - decline rather than guess.
1443
+ return { ok: false, reason: 'unserializable' };
1444
+ }
1445
+ }
1446
+
1233
1447
  /**
1234
1448
  * Load Coordinator - Request deduplication for component on_load() calls
1235
1449
  *
@@ -1266,8 +1480,9 @@ class Load_Coordinator {
1266
1480
  * - key: Cache key string, or null if uncacheable
1267
1481
  * - uncacheable_property: Name of first property that prevented caching (for debugging)
1268
1482
  */
1269
- static generate_invocation_key(component_name, args) {
1483
+ static generate_invocation_key(component_name, args, options = {}) {
1270
1484
  let uncacheable_property;
1485
+ let uncacheable_reason;
1271
1486
  // Filter out internal properties (starting with _) and serialize args
1272
1487
  const serializable_args = {};
1273
1488
  for (const key of Object.keys(args).sort()) {
@@ -1306,21 +1521,37 @@ class Load_Coordinator {
1306
1521
  // Method threw error - treat as uncacheable
1307
1522
  if (!uncacheable_property) {
1308
1523
  uncacheable_property = key;
1524
+ uncacheable_reason = 'cache-id-threw';
1309
1525
  }
1310
- return { key: null, uncacheable_property };
1526
+ return { key: null, uncacheable_property, uncacheable_reason };
1527
+ }
1528
+ }
1529
+ // No author-supplied id. The cache may fall back to keying by
1530
+ // deterministic content; deduplication deliberately may not.
1531
+ if (options.allow_content_serialization) {
1532
+ const serialized = serialize_for_cache_key(value);
1533
+ if (serialized.ok) {
1534
+ serializable_args[key] = `__JQHTML_CONTENT__:${serialized.text}`;
1535
+ continue;
1311
1536
  }
1537
+ if (!uncacheable_property) {
1538
+ uncacheable_property = key;
1539
+ uncacheable_reason = serialized.reason;
1540
+ }
1541
+ return { key: null, uncacheable_property, uncacheable_reason };
1312
1542
  }
1313
- // No cache ID available - this property is uncacheable
1314
1543
  if (!uncacheable_property) {
1315
1544
  uncacheable_property = key;
1545
+ uncacheable_reason = value_type === 'function' ? 'function' : 'object';
1316
1546
  }
1317
- return { key: null, uncacheable_property };
1547
+ return { key: null, uncacheable_property, uncacheable_reason };
1318
1548
  }
1319
1549
  // Unknown type (symbol, bigint, etc.) - uncacheable
1320
1550
  if (!uncacheable_property) {
1321
1551
  uncacheable_property = key;
1552
+ uncacheable_reason = value_type;
1322
1553
  }
1323
- return { key: null, uncacheable_property };
1554
+ return { key: null, uncacheable_property, uncacheable_reason };
1324
1555
  }
1325
1556
  // Try to serialize - if it fails (shouldn't happen now, but safety net), return null
1326
1557
  try {
@@ -1338,6 +1569,12 @@ class Load_Coordinator {
1338
1569
  */
1339
1570
  static should_execute_on_load(component) {
1340
1571
  const { key } = this.generate_invocation_key(component.component_name(), component.args);
1572
+ // No identity means no coordination. Without this, every un-keyable component
1573
+ // would share the single `null` registry entry and adopt an unrelated
1574
+ // component's data - the worst failure this system can produce.
1575
+ if (key === null) {
1576
+ return true;
1577
+ }
1341
1578
  const entry = this._registry.get(key);
1342
1579
  if (!entry) {
1343
1580
  // No existing request - this component becomes the leader
@@ -1360,6 +1597,10 @@ class Load_Coordinator {
1360
1597
  */
1361
1598
  static register_leader(component, on_load_promise) {
1362
1599
  const { key } = this.generate_invocation_key(component.component_name(), component.args);
1600
+ // Un-keyable component: run alone, register nothing. See should_execute_on_load().
1601
+ if (key === null) {
1602
+ return () => { };
1603
+ }
1363
1604
  // Create a promise that we control - it resolves when complete_coordination is called
1364
1605
  let resolve_promise;
1365
1606
  const coordination_promise = new Promise((resolve) => {
@@ -1581,6 +1822,8 @@ Load_Coordinator._registry = new Map();
1581
1822
  // Registry mapping class names to constructors
1582
1823
  const class_registry = Object.create(null);
1583
1824
  // Markers for serialized class instances (unique to avoid collisions with user data)
1825
+ // Replaced at build time by rollup (see rollup.config.js).
1826
+ const CORE_VERSION = '2.3.54';
1584
1827
  const CLASS_MARKER = '__jqhtml_class__';
1585
1828
  const PROPS_MARKER = '__jqhtml_props__';
1586
1829
  /**
@@ -1870,6 +2113,12 @@ class Jqhtml_Local_Storage {
1870
2113
  */
1871
2114
  static set_cache_key(cache_key, cache_mode = 'data') {
1872
2115
  this._cache_key = cache_key;
2116
+ // Key SHAPE is a function of the library (see cache-key-serializer.ts), so an
2117
+ // upgrade that changes it must invalidate everything persisted under the old shape.
2118
+ // Version the SCOPE MARKER rather than the key itself: _validate_scope() already
2119
+ // clears every jqhtml key when this value changes, and leaving the per-entry key
2120
+ // format alone keeps stored keys readable and avoids repeating the version in each.
2121
+ this._scope_marker = `${CORE_VERSION}::${cache_key}`;
1873
2122
  this._cache_mode = cache_mode;
1874
2123
  this._init();
1875
2124
  }
@@ -1939,21 +2188,21 @@ class Jqhtml_Local_Storage {
1939
2188
  }
1940
2189
  try {
1941
2190
  const stored_key = localStorage.getItem('_jqhtml_cache_key');
1942
- // If cache key exists and has changed, clear only JQHTML keys
1943
- if (stored_key !== null && stored_key !== this._cache_key) {
1944
- console.log('[JQHTML Local Storage] Cache key changed, clearing JQHTML keys:', {
2191
+ // If the scope marker (core version + developer key) changed, clear only JQHTML keys
2192
+ if (stored_key !== null && stored_key !== this._scope_marker) {
2193
+ console.log('[JQHTML Local Storage] Cache scope changed, clearing JQHTML keys:', {
1945
2194
  old_key: stored_key,
1946
- new_key: this._cache_key,
2195
+ new_key: this._scope_marker,
1947
2196
  });
1948
2197
  this._clear_jqhtml_keys();
1949
- localStorage.setItem('_jqhtml_cache_key', this._cache_key);
2198
+ localStorage.setItem('_jqhtml_cache_key', this._scope_marker);
1950
2199
  }
1951
2200
  else if (stored_key === null) {
1952
2201
  // First time JQHTML is using this storage - just set the key, don't clear
1953
- console.log('[JQHTML Local Storage] Initializing cache key (first use):', {
1954
- new_key: this._cache_key,
2202
+ console.log('[JQHTML Local Storage] Initializing cache scope (first use):', {
2203
+ new_key: this._scope_marker,
1955
2204
  });
1956
- localStorage.setItem('_jqhtml_cache_key', this._cache_key);
2205
+ localStorage.setItem('_jqhtml_cache_key', this._scope_marker);
1957
2206
  }
1958
2207
  }
1959
2208
  catch (e) {
@@ -2185,6 +2434,8 @@ class Jqhtml_Local_Storage {
2185
2434
  }
2186
2435
  }
2187
2436
  Jqhtml_Local_Storage._cache_key = null;
2437
+ /** Versioned scope identity - compared in _validate_scope() to clear on a core upgrade. */
2438
+ Jqhtml_Local_Storage._scope_marker = null;
2188
2439
  Jqhtml_Local_Storage._cache_mode = 'data';
2189
2440
  Jqhtml_Local_Storage._storage_available = null;
2190
2441
  Jqhtml_Local_Storage._initialized = false;
@@ -2282,10 +2533,15 @@ function event_once(component, event_name, callback) {
2282
2533
  function event_trigger(component, event_name, data) {
2283
2534
  // Mark this event as occurred and store the data for late subscribers
2284
2535
  component._lifecycle_states.set(event_name, data);
2285
- // Fire all registered callbacks for this event
2536
+ // Fire all registered callbacks for this event.
2537
+ // Iterate a SNAPSHOT: handlers registered via once() splice themselves out of the
2538
+ // live array while it is being iterated, which would shift later handlers into
2539
+ // already-visited slots and skip them. The snapshot also means a handler
2540
+ // registered during dispatch does not fire in this dispatch (event_on's sticky
2541
+ // immediate-fire already delivered it).
2286
2542
  const callbacks = component._lifecycle_callbacks.get(event_name);
2287
2543
  if (callbacks) {
2288
- for (const callback of callbacks) {
2544
+ for (const callback of [...callbacks]) {
2289
2545
  try {
2290
2546
  callback.bind(component)(component, data);
2291
2547
  }
@@ -2570,12 +2826,73 @@ function generate_cache_key(component) {
2570
2826
  return { cache_key: `${component.component_name()}::${String(custom_cache_id)}` };
2571
2827
  }
2572
2828
  catch (error) {
2573
- return { cache_key: null, uncacheable_property: 'cache_id()' };
2829
+ return { cache_key: null, uncacheable_property: 'cache_id()', uncacheable_reason: 'cache-id-threw' };
2574
2830
  }
2575
2831
  }
2576
- // Use standard args-based cache key generation
2577
- const result = Load_Coordinator.generate_invocation_key(component.component_name(), component.args);
2578
- return { cache_key: result.key, uncacheable_property: result.uncacheable_property };
2832
+ // Standard args-based key. The CACHE opts into content serialization for plain-data
2833
+ // object args; deduplication does not - see InvocationKeyOptions for why.
2834
+ const result = Load_Coordinator.generate_invocation_key(component.component_name(), component.args, { allow_content_serialization: true });
2835
+ return {
2836
+ cache_key: result.key,
2837
+ uncacheable_property: result.uncacheable_property,
2838
+ uncacheable_reason: result.uncacheable_reason,
2839
+ };
2840
+ }
2841
+ // One warning per component+property. A list of 50 rows must not print 50 warnings.
2842
+ const _warned_uncacheable = new Set();
2843
+ /**
2844
+ * Development warning: this component fetches data but cannot be cached, because
2845
+ * its args do not reduce to a stable key and it defines no cache_id() to say what
2846
+ * its identity is. Nothing is broken - the component works - but it silently opts
2847
+ * out of cache reuse and of load deduplication.
2848
+ *
2849
+ * Controlled by the `warn_uncacheable_args` integration flag (see config.ts).
2850
+ */
2851
+ function warn_uncacheable_component(component, uncacheable_property, uncacheable_reason) {
2852
+ if (!warn_uncacheable_args_enabled())
2853
+ return;
2854
+ let name = 'unknown';
2855
+ try {
2856
+ name = component.component_name();
2857
+ }
2858
+ catch { /* name unavailable */ }
2859
+ const dedupe_key = `${name}::${uncacheable_property || '?'}::${uncacheable_reason || '?'}`;
2860
+ if (_warned_uncacheable.has(dedupe_key))
2861
+ return;
2862
+ _warned_uncacheable.add(dedupe_key);
2863
+ // cache_id() exists but threw - a different problem with a different fix
2864
+ if (uncacheable_property === 'cache_id()' || uncacheable_reason === 'cache-id-threw') {
2865
+ console.warn(`[JQHTML] <${name}> defines cache_id() but it threw, so this component is not cached ` +
2866
+ `and its loads are not deduplicated. Fix cache_id() so it returns a stable string.`, { component: name, cid: component._cid });
2867
+ return;
2868
+ }
2869
+ const REASONS = {
2870
+ 'function': 'it contains a function - a callback is real identity that content cannot express',
2871
+ 'symbol': 'it contains a symbol',
2872
+ 'bigint': 'it contains a bigint',
2873
+ 'dom-node': 'it contains a DOM node',
2874
+ 'jquery': 'it contains a jQuery object',
2875
+ 'circular': 'it contains a circular reference',
2876
+ 'non-plain-object': 'it contains a class instance, Map, Set or similar - only plain objects and arrays can be keyed by content',
2877
+ 'too-large': 'it serializes to more than 500 bytes - args are meant to identify data, not carry it',
2878
+ 'invalid-date': 'it contains an invalid Date',
2879
+ };
2880
+ const why = REASONS[uncacheable_reason || ''] || 'it cannot be serialized deterministically';
2881
+ console.warn(`[JQHTML] <${name}> cannot be cached: arg $${uncacheable_property} is not keyable because ` +
2882
+ `${why}.\n` +
2883
+ ` The component works, but it will not be restored from cache when reused.\n` +
2884
+ ` Fix: define cache_id() on the component to state its identity explicitly, e.g.\n` +
2885
+ ` cache_id() { return \`${name.toLowerCase()}_\${this.args.some_id}\`; }\n` +
2886
+ ` Or pass plain data (objects/arrays of primitives are keyed automatically) instead of ` +
2887
+ `$${uncacheable_property}.\n` +
2888
+ ` Find it in DevTools with the selector ` +
2889
+ `[data-nocache="${uncacheable_property}:${uncacheable_reason || ''}"].`, {
2890
+ component: name,
2891
+ cid: component._cid,
2892
+ uncacheable_arg: uncacheable_property,
2893
+ reason: uncacheable_reason,
2894
+ all_args: component.args ? Object.keys(component.args) : [],
2895
+ });
2579
2896
  }
2580
2897
  /**
2581
2898
  * Read cache during create() phase.
@@ -2584,13 +2901,15 @@ function generate_cache_key(component) {
2584
2901
  * @param component - The component instance
2585
2902
  */
2586
2903
  function read_cache_in_create(component) {
2587
- const { cache_key, uncacheable_property } = generate_cache_key(component);
2904
+ const { cache_key, uncacheable_property, uncacheable_reason } = generate_cache_key(component);
2588
2905
  // If cache_key is null, caching disabled
2589
2906
  if (cache_key === null) {
2590
2907
  // Set data-nocache attribute for debugging
2591
2908
  if (uncacheable_property) {
2592
- component.$.attr('data-nocache', uncacheable_property);
2909
+ // "<arg>:<reason>" - a bare property name left authors reverse-engineering why
2910
+ component.$.attr('data-nocache', uncacheable_reason ? `${uncacheable_property}:${uncacheable_reason}` : uncacheable_property);
2593
2911
  }
2912
+ warn_uncacheable_component(component, uncacheable_property, uncacheable_reason);
2594
2913
  if (window.jqhtml?.debug?.verbose) {
2595
2914
  console.log(`[Cache] Component ${component._cid} (${component.component_name()}) has non-serializable args - caching disabled`, { uncacheable_property });
2596
2915
  }
@@ -3004,6 +3323,75 @@ function has_preload_data() {
3004
3323
  return _preload_cache.size > 0;
3005
3324
  }
3006
3325
 
3326
+ /**
3327
+ * JQHTML Viewport Resize Dispatch
3328
+ *
3329
+ * One framework-owned, debounced window 'resize' listener fans out to every live
3330
+ * component in the document by calling on_viewport_resize(viewport_width).
3331
+ *
3332
+ * Components never bind their own window listener, so there is nothing to unbind
3333
+ * in on_stop() - a component that is stopped or removed from the document simply
3334
+ * stops being found by the dispatcher.
3335
+ */
3336
+ /** Trailing-edge debounce applied to the window resize listener. */
3337
+ const VIEWPORT_RESIZE_DEBOUNCE_MS = 30;
3338
+ let debounce_timer = null;
3339
+ let listener_installed = false;
3340
+ /**
3341
+ * Current viewport width in CSS pixels.
3342
+ *
3343
+ * window.innerWidth is used (not $(window).width()) because it matches the width
3344
+ * CSS media queries resolve against. It includes the scrollbar gutter.
3345
+ *
3346
+ * Returns 0 outside a browser (SSR).
3347
+ */
3348
+ function get_viewport_width() {
3349
+ return typeof window !== 'undefined' ? window.innerWidth : 0;
3350
+ }
3351
+ /**
3352
+ * Call on_viewport_resize(width) on every component currently in the document.
3353
+ *
3354
+ * Walks $('.Component') in document order (parents before children). Elements
3355
+ * with no component instance and stopped components are skipped. A component
3356
+ * that throws is logged and the walk continues - one bad handler must not stop
3357
+ * the rest of the page from resizing.
3358
+ */
3359
+ function dispatch_viewport_resize(jQuery) {
3360
+ const viewport_width = get_viewport_width();
3361
+ jQuery('.Component').each(function () {
3362
+ const component = jQuery(this).data('_component');
3363
+ if (!component || component._stopped)
3364
+ return;
3365
+ if (typeof component.on_viewport_resize !== 'function')
3366
+ return;
3367
+ try {
3368
+ component.on_viewport_resize(viewport_width);
3369
+ }
3370
+ catch (error) {
3371
+ console.error(`[JQHTML] Error in on_viewport_resize() for ${component.component_name?.() || 'component'}:`, error);
3372
+ }
3373
+ });
3374
+ }
3375
+ /**
3376
+ * Install the single window resize listener. Idempotent - repeated init() calls
3377
+ * and non-browser environments are no-ops.
3378
+ */
3379
+ function init_viewport_resize(jQuery) {
3380
+ if (typeof window === 'undefined')
3381
+ return;
3382
+ if (listener_installed)
3383
+ return;
3384
+ listener_installed = true;
3385
+ jQuery(window).on('resize.jqhtml_viewport', function () {
3386
+ if (debounce_timer !== null)
3387
+ clearTimeout(debounce_timer);
3388
+ debounce_timer = setTimeout(function () {
3389
+ debounce_timer = null;
3390
+ dispatch_viewport_resize(jQuery);
3391
+ }, VIEWPORT_RESIZE_DEBOUNCE_MS);
3392
+ });
3393
+ }
3394
+
3007
3395
  /**
3008
3396
  * JQHTML v2 Component Base Class
3009
3397
  *
@@ -3198,6 +3586,21 @@ class Jqhtml_Component {
3198
3586
  // Call original directly - no flag needed since we bypass the wrapper
3199
3587
  return impl.call(this);
3200
3588
  }
3589
+ /**
3590
+ * Fire on_viewport_resize() with the current viewport width.
3591
+ * Called after every on_render() and on_ready(); the debounced window
3592
+ * listener in viewport.ts drives it from then on. Errors are isolated so a
3593
+ * bad handler cannot break the lifecycle.
3594
+ * @private
3595
+ */
3596
+ _fire_viewport_resize() {
3597
+ try {
3598
+ this.on_viewport_resize(get_viewport_width());
3599
+ }
3600
+ catch (error) {
3601
+ console.error(`[JQHTML] Error in on_viewport_resize() for ${this.component_name()}:`, error);
3602
+ }
3603
+ }
3201
3604
  /**
3202
3605
  * Check if on_load() is overridden in a subclass
3203
3606
  * Used to skip the load phase entirely for components that don't fetch data
@@ -3282,6 +3685,7 @@ class Jqhtml_Component {
3282
3685
  console.warn(`[JQHTML] Component "${this.component_name()}" returned a Promise from on_render(). ` +
3283
3686
  `on_render() must be synchronous code. Remove 'async' from the function declaration.`);
3284
3687
  }
3688
+ this._fire_viewport_resize();
3285
3689
  }
3286
3690
  // Emit lifecycle event
3287
3691
  this.trigger('render');
@@ -3473,6 +3877,7 @@ class Jqhtml_Component {
3473
3877
  console.warn(`[JQHTML] Component "${this.component_name()}" returned a Promise from on_render(). ` +
3474
3878
  `on_render() must be synchronous code. Remove 'async' from the function declaration.`);
3475
3879
  }
3880
+ this._fire_viewport_resize();
3476
3881
  }
3477
3882
  // Emit lifecycle event
3478
3883
  this.trigger('render');
@@ -3547,6 +3952,7 @@ class Jqhtml_Component {
3547
3952
  }
3548
3953
  // Call on_ready hook with authorization
3549
3954
  await this._call_lifecycle('on_ready');
3955
+ this._fire_viewport_resize();
3550
3956
  // Trigger ready event
3551
3957
  this.trigger('ready');
3552
3958
  });
@@ -3773,9 +4179,18 @@ class Jqhtml_Component {
3773
4179
  }
3774
4180
  return;
3775
4181
  }
3776
- // Generate cache key (needed for both preload check and load deduplication)
4182
+ // TWO identities, deliberately computed separately.
4183
+ //
4184
+ // cache_key - may key a plain-data object arg by deterministic CONTENT, and may come
4185
+ // from the author's cache_id(). A wrong key here is corrected by
4186
+ // stale-while-revalidate.
4187
+ // dedup_key - args only, no content serialization, no cache_id(). A deduplicated
4188
+ // follower never runs on_load() and adopts the leader's data with NO
4189
+ // revalidation, so a wrong key here is permanently wrong data. Redundant
4190
+ // concurrent requests are the cheaper failure.
3777
4191
  let cache_key = null;
3778
4192
  let uncacheable_property;
4193
+ let uncacheable_reason;
3779
4194
  if (typeof this.cache_id === 'function') {
3780
4195
  try {
3781
4196
  const custom_cache_id = this.cache_id();
@@ -3784,14 +4199,16 @@ class Jqhtml_Component {
3784
4199
  catch (error) {
3785
4200
  // cache_id() threw error - disable caching
3786
4201
  uncacheable_property = 'cache_id()';
4202
+ uncacheable_reason = 'cache-id-threw';
3787
4203
  }
3788
4204
  }
3789
4205
  else {
3790
- // Use standard args-based cache key generation
3791
- const result = Load_Coordinator.generate_invocation_key(this.component_name(), this.args);
4206
+ const result = Load_Coordinator.generate_invocation_key(this.component_name(), this.args, { allow_content_serialization: true });
3792
4207
  cache_key = result.key;
3793
4208
  uncacheable_property = result.uncacheable_property;
4209
+ uncacheable_reason = result.uncacheable_reason;
3794
4210
  }
4211
+ const dedup_key = Load_Coordinator.generate_invocation_key(this.component_name(), this.args).key;
3795
4212
  // SSR preload check: if preloaded data exists for this component+args, use it
3796
4213
  if (cache_key !== null && has_preload_data()) {
3797
4214
  const preloaded_data = consume_preload_data(cache_key);
@@ -3807,23 +4224,24 @@ class Jqhtml_Component {
3807
4224
  }
3808
4225
  // Store cache key for later use
3809
4226
  this._cache_key = cache_key;
3810
- // If cache_key is null, args are not serializable - skip load deduplication and caching
3811
- if (cache_key === null) {
3812
- // Set data-nocache attribute for debugging (shows which property prevented caching)
3813
- if (uncacheable_property) {
3814
- this.$.attr('data-nocache', uncacheable_property);
4227
+ // Caching disabled - mark the element with the offending arg AND why
4228
+ if (cache_key === null && uncacheable_property) {
4229
+ this.$.attr('data-nocache', uncacheable_reason ? `${uncacheable_property}:${uncacheable_reason}` : uncacheable_property);
4230
+ if (window.jqhtml?.debug?.verbose) {
4231
+ console.log(`[Cache] Component ${this._cid} (${this.component_name()}) has non-keyable args - caching disabled`, { uncacheable_property, uncacheable_reason });
3815
4232
  }
4233
+ }
4234
+ // Store "before" snapshot for comparison after on_load()
4235
+ const data_before_load = JSON.stringify(this.data);
4236
+ // No dedup identity - run on_load() alone rather than risk sharing a load
4237
+ if (dedup_key === null) {
3816
4238
  if (window.jqhtml?.debug?.verbose) {
3817
- console.log(`[Cache] Component ${this._cid} (${this.component_name()}) has non-serializable args - load deduplication and caching disabled`, { uncacheable_property });
4239
+ console.log(`[Load Deduplication] Component ${this._cid} (${this.component_name()}) has no dedup key - loading independently`);
3818
4240
  }
3819
- // Execute on_load on detached proxy without deduplication
3820
4241
  const { data: result_data } = await this._execute_on_load_detached();
3821
- // Apply result via sequential queue
3822
- await this._apply_load_result(result_data, null);
4242
+ await this._apply_load_result(result_data, data_before_load);
3823
4243
  return;
3824
4244
  }
3825
- // Store "before" snapshot for comparison after on_load()
3826
- const data_before_load = JSON.stringify(this.data);
3827
4245
  // Check if this component should execute on_load() or wait for existing request
3828
4246
  const should_execute = Load_Coordinator.should_execute_on_load(this);
3829
4247
  if (!should_execute) {
@@ -3972,6 +4390,7 @@ class Jqhtml_Component {
3972
4390
  // Wait for all children to reach ready state (bottom-up execution)
3973
4391
  await this._wait_for_children_ready();
3974
4392
  await this._call_lifecycle('on_ready');
4393
+ this._fire_viewport_resize();
3975
4394
  this._ready_state = 4;
3976
4395
  this._update_debug_attrs();
3977
4396
  this._log_lifecycle('ready', 'complete');
@@ -4216,6 +4635,7 @@ class Jqhtml_Component {
4216
4635
  this._render();
4217
4636
  await this._wait_for_children_ready();
4218
4637
  await this._call_lifecycle('on_ready');
4638
+ this._fire_viewport_resize();
4219
4639
  this.trigger('ready');
4220
4640
  this._log_lifecycle('reload', 'complete (no on_load)');
4221
4641
  return;
@@ -4290,6 +4710,7 @@ class Jqhtml_Component {
4290
4710
  if (rendered_from_cache || should_render) {
4291
4711
  await this._wait_for_children_ready();
4292
4712
  await this._call_lifecycle('on_ready');
4713
+ this._fire_viewport_resize();
4293
4714
  // Trigger ready event so parent callbacks fire on subsequent reloads
4294
4715
  this.trigger('ready');
4295
4716
  }
@@ -4372,6 +4793,16 @@ class Jqhtml_Component {
4372
4793
  on_loaded() { } // Override to process loaded data (e.g., clone this.data to this.state)
4373
4794
  async on_ready() { }
4374
4795
  on_stop() { }
4796
+ /**
4797
+ * Called with the viewport width in CSS pixels:
4798
+ * - after every on_render()
4799
+ * - after every on_ready()
4800
+ * - on window resize, debounced 30ms, for every component in the document
4801
+ *
4802
+ * MUST be synchronous. Prefer CSS media/container queries for pure styling -
4803
+ * override this only when layout requires imperative measurement.
4804
+ */
4805
+ on_viewport_resize(viewport_width) { }
4375
4806
  /**
4376
4807
  * Should component re-render after load?
4377
4808
  * By default, only re-renders if data has changed
@@ -4746,8 +5177,13 @@ class Jqhtml_Component {
4746
5177
  }
4747
5178
  }
4748
5179
  _set_attributes() {
4749
- // Always set data-cid
4750
- this.$.attr('data-cid', this._cid);
5180
+ // data-cid on the rendered element is debug-only: it mirrors this._cid so component
5181
+ // boundaries are legible in DevTools. The runtime never reads it - scoping uses the
5182
+ // _cid property, and the transient data-cid placeholder the instruction processor
5183
+ // matches on is written and removed before this ever runs.
5184
+ if (debug_attributes_enabled()) {
5185
+ this.$.attr('data-cid', this._cid);
5186
+ }
4751
5187
  // Only set lifecycle state attribute if verbose mode enabled
4752
5188
  if (window.jqhtml?.debug?.verbose) {
4753
5189
  this.$.attr('data-_lifecycle-state', this._ready_state.toString());
@@ -5686,6 +6122,9 @@ function init_jquery_plugin(jQuery) {
5686
6122
  PatchedInit.prototype = jQuery.fn;
5687
6123
  jQuery.fn.init = PatchedInit;
5688
6124
  }
6125
+ // Install the single debounced window resize listener that drives
6126
+ // on_viewport_resize() on every component. Idempotent.
6127
+ init_viewport_resize(jQuery);
5689
6128
  }
5690
6129
  // Try to auto-initialize if global jQuery exists
5691
6130
  if (typeof window !== 'undefined' && window.jQuery) {
@@ -5699,7 +6138,9 @@ if (typeof window !== 'undefined' && window.jQuery) {
5699
6138
  */
5700
6139
  // Core exports
5701
6140
  // Main initialization function
5702
- function init(jQuery) {
6141
+ function init(jQuery, config) {
6142
+ // Integration config first - it governs behaviour during the very first render
6143
+ configure(config);
5703
6144
  // If jQuery is provided, initialize the plugin
5704
6145
  if (jQuery) {
5705
6146
  init_jquery_plugin(jQuery);
@@ -5713,7 +6154,7 @@ function init(jQuery) {
5713
6154
  }
5714
6155
  }
5715
6156
  // Version - will be replaced during build with actual version from package.json
5716
- const version = '2.3.50';
6157
+ const version = '2.3.54';
5717
6158
  // Default export with all functionality
5718
6159
  const jqhtml = {
5719
6160
  // Core
@@ -5741,6 +6182,9 @@ const jqhtml = {
5741
6182
  __version: version,
5742
6183
  // state facts
5743
6184
  tombstone: 'pepperoni and cheese',
6185
+ // Integration configuration - see config.ts
6186
+ configure,
6187
+ get_config,
5744
6188
  // Debug settings
5745
6189
  debug: {
5746
6190
  enabled: false,
@@ -5854,6 +6298,7 @@ exports.Load_Coordinator = Load_Coordinator;
5854
6298
  exports.applyDebugDelay = applyDebugDelay;
5855
6299
  exports.boot = boot;
5856
6300
  exports.clear_preload_data = clear_preload_data;
6301
+ exports.configure = configure;
5857
6302
  exports.create_component = create_component;
5858
6303
  exports.default = jqhtml;
5859
6304
  exports.devWarn = devWarn;
@@ -5863,6 +6308,7 @@ exports.extract_slots = extract_slots;
5863
6308
  exports.get_captured_data = get_captured_data;
5864
6309
  exports.get_component_class = get_component_class;
5865
6310
  exports.get_component_names = get_component_names;
6311
+ exports.get_config = get_config;
5866
6312
  exports.get_registered_templates = get_registered_templates;
5867
6313
  exports.get_template = get_template;
5868
6314
  exports.get_template_by_class = get_template_by_class;