gyosjs 0.5.5 → 0.5.7

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/gyos.csp.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * GyosJS v0.5.5
2
+ * GyosJS v0.5.7
3
3
  * (c) 2026
4
4
  * @license MIT
5
5
  */
@@ -9452,7 +9452,8 @@
9452
9452
  const propertyName = booleanPropertyNames[attrName] || attrName;
9453
9453
  if (propertyName in element) {
9454
9454
  try {
9455
- element[propertyName] = value;
9455
+ if (element[propertyName] !== value)
9456
+ element[propertyName] = value;
9456
9457
  }
9457
9458
  catch {
9458
9459
  // Some reflected DOM properties are read-only in older engines.
@@ -9483,9 +9484,14 @@
9483
9484
  }
9484
9485
  const stringValue = String(value);
9485
9486
  if (attrName === 'value' && 'value' in element) {
9486
- element.value = stringValue;
9487
+ // Compare the live control, not a cached expression: user edits and
9488
+ // external DOM changes still need reconciliation on the next update.
9489
+ if (element.value !== stringValue) {
9490
+ element.value = stringValue;
9491
+ }
9487
9492
  }
9488
- element.setAttribute(attrName, stringValue);
9493
+ if (element.getAttribute(attrName) !== stringValue)
9494
+ element.setAttribute(attrName, stringValue);
9489
9495
  }
9490
9496
  function boundAttributes(element) {
9491
9497
  return Array.from(element.attributes).filter(attribute => attribute.name.startsWith(':'));
@@ -14793,7 +14799,6 @@
14793
14799
  }
14794
14800
  const snapshots = new Map();
14795
14801
  const preloadCache = new Map();
14796
- const preloadControllers = new Map();
14797
14802
  const scrollPositions = new Map();
14798
14803
  const historyFragments = new Map();
14799
14804
  let routerStarted = false;
@@ -15113,6 +15118,15 @@
15113
15118
  }
15114
15119
  return { finalUrl: url.toString(), init };
15115
15120
  }
15121
+ function discardPreload(key) {
15122
+ const entry = preloadCache.get(key);
15123
+ preloadCache.delete(key);
15124
+ entry?.controller.abort();
15125
+ }
15126
+ function clearPreloads() {
15127
+ for (const key of preloadCache.keys())
15128
+ discardPreload(key);
15129
+ }
15116
15130
  function preload(url) {
15117
15131
  const cacheKey = canonicalUrl(url, true);
15118
15132
  if (preloadCache.has(cacheKey))
@@ -15127,11 +15141,11 @@
15127
15141
  signal: controller.signal,
15128
15142
  mode: 'same-origin'
15129
15143
  });
15130
- preloadCache.set(cacheKey, request);
15131
- preloadControllers.set(cacheKey, controller);
15144
+ const entry = { request, controller };
15145
+ preloadCache.set(cacheKey, entry);
15132
15146
  request.catch(() => {
15133
- preloadCache.delete(cacheKey);
15134
- preloadControllers.delete(cacheKey);
15147
+ if (preloadCache.get(cacheKey) === entry)
15148
+ preloadCache.delete(cacheKey);
15135
15149
  });
15136
15150
  }
15137
15151
  async function updateHead(fromDoc, signal, currentBaseUrl) {
@@ -15310,20 +15324,21 @@
15310
15324
  else {
15311
15325
  // Check preload cache if GET
15312
15326
  const preloadKey = canonicalUrl(finalUrl, true);
15313
- if (opts.fresh) {
15314
- preloadControllers.get(preloadKey)?.abort();
15315
- preloadControllers.delete(preloadKey);
15316
- preloadCache.delete(preloadKey);
15317
- }
15318
- if (!opts.fresh && opts.method.toUpperCase() === 'GET' && preloadCache.has(preloadKey)) {
15327
+ if (opts.fresh)
15328
+ discardPreload(preloadKey);
15329
+ const entry = init.method === 'GET' ? preloadCache.get(preloadKey) : undefined;
15330
+ if (entry) {
15319
15331
  log('[GyosRouter] using preload cache for', finalUrl);
15332
+ const signal = transaction.controller.signal;
15333
+ const discard = () => {
15334
+ if (preloadCache.get(preloadKey) === entry)
15335
+ discardPreload(preloadKey);
15336
+ };
15337
+ signal.addEventListener('abort', discard, { once: true });
15320
15338
  try {
15321
- response = await waitForNavigation(preloadCache.get(preloadKey), transaction.controller.signal);
15339
+ response = await waitForNavigation(entry.request, signal);
15322
15340
  }
15323
15341
  catch (error) {
15324
- preloadCache.delete(preloadKey);
15325
- preloadControllers.get(preloadKey)?.abort();
15326
- preloadControllers.delete(preloadKey);
15327
15342
  if (error.name === 'AbortError')
15328
15343
  throw error;
15329
15344
  assertActiveNavigation(transaction);
@@ -15331,8 +15346,11 @@
15331
15346
  fallback(finalUrl, true);
15332
15347
  return;
15333
15348
  }
15334
- preloadCache.delete(preloadKey); // consume cache
15335
- preloadControllers.delete(preloadKey);
15349
+ finally {
15350
+ signal.removeEventListener('abort', discard);
15351
+ if (preloadCache.get(preloadKey) === entry)
15352
+ preloadCache.delete(preloadKey);
15353
+ }
15336
15354
  }
15337
15355
  else {
15338
15356
  try {
@@ -15341,6 +15359,9 @@
15341
15359
  transaction.interval = setInterval(setRand, 300);
15342
15360
  response = await fetch(finalUrl, init);
15343
15361
  assertActiveNavigation(transaction);
15362
+ // A successful write can change HTML at any URL, including after a redirect.
15363
+ if (response.ok && init.method !== 'GET')
15364
+ clearPreloads();
15344
15365
  // Update progress to rand 70 - 80% after fetch
15345
15366
  progressBar?.setProgress(Math.random() * 10 + 70);
15346
15367
  if (transaction.interval)
@@ -15480,6 +15501,15 @@
15480
15501
  // The global outlet is also the incoming layout root. Keep its node for
15481
15502
  // inner swaps, but update attributes such as g-scope and layout classes.
15482
15503
  try {
15504
+ if (syncDocumentAttributes && !document.querySelector('base[href]')) {
15505
+ document.head.querySelectorAll('base[target]').forEach(base => base.remove());
15506
+ const baseTarget = doc.head.querySelector('base[target]')?.getAttribute('target');
15507
+ if (baseTarget != null) {
15508
+ const base = document.createElement('base');
15509
+ base.target = baseTarget;
15510
+ document.head.prepend(base);
15511
+ }
15512
+ }
15483
15513
  target = await performSwap(target, src, swapMode, {
15484
15514
  syncRootAttributes: isFullOutletNavigation,
15485
15515
  signal: transaction.controller.signal,
@@ -15605,10 +15635,39 @@
15605
15635
  opts.onEnd?.({ ...context });
15606
15636
  }
15607
15637
  }
15608
- function shouldBoost(el) {
15609
- if (el.closest('[g-no-boost]'))
15610
- return false;
15611
- return el.hasAttribute('g-boost') || hasGlobalBoost();
15638
+ function eligibleAnchorUrl(link) {
15639
+ if (!(link instanceof HTMLAnchorElement) || !link.getAttribute('href')
15640
+ || link.hasAttribute('download') || link.closest('[g-no-boost]'))
15641
+ return null;
15642
+ const target = link.getAttribute('target') ?? document.querySelector('base[target]')?.getAttribute('target');
15643
+ if (target && target.toLowerCase() !== '_self')
15644
+ return null;
15645
+ let url;
15646
+ try {
15647
+ url = new URL(link.href);
15648
+ }
15649
+ catch {
15650
+ return null;
15651
+ }
15652
+ if (!['http:', 'https:'].includes(url.protocol) || url.origin !== location.origin
15653
+ || url.username || url.password)
15654
+ return null;
15655
+ // URL.hash is empty for both an absent fragment and a trailing "#".
15656
+ if (url.href.includes('#') && canonicalUrl(url.href) === canonicalUrl(location.href))
15657
+ return null;
15658
+ // A page visit would need to remove the outgoing base before inserting
15659
+ // relative resources. Let the browser switch documents and enforce base-uri.
15660
+ if (document.querySelector('base[href]') && !link.hasAttribute('g-current-head')
15661
+ && !['append', 'prepend'].includes(link.getAttribute('g-swap')?.toLowerCase() || '')) {
15662
+ try {
15663
+ if (resolveTarget(link) === findGlobalOutlet())
15664
+ return null;
15665
+ }
15666
+ catch {
15667
+ return null;
15668
+ }
15669
+ }
15670
+ return url;
15612
15671
  }
15613
15672
  function onClickRouter(element) {
15614
15673
  log('[GyosRouter] g-router-link clicked');
@@ -15662,23 +15721,10 @@
15662
15721
  return;
15663
15722
  }
15664
15723
  const link = target.closest('a');
15665
- if (!link)
15724
+ if (!link || !(link.hasAttribute('g-boost') || hasGlobalBoost()))
15666
15725
  return;
15667
- const href = link.getAttribute('href');
15668
- if (!href)
15669
- return;
15670
- const url = new URL(href, window.location.href);
15671
- if (url.origin !== window.location.origin)
15672
- return;
15673
- if (url.hash && canonicalUrl(url.href) === canonicalUrl(window.location.href))
15674
- return;
15675
- if (link.closest('[g-no-boost]'))
15676
- return;
15677
- if (link.hasAttribute('download'))
15678
- return;
15679
- if (link.getAttribute('target') && link.getAttribute('target') !== '_self')
15680
- return;
15681
- if (!shouldBoost(link))
15726
+ const url = eligibleAnchorUrl(link);
15727
+ if (!url)
15682
15728
  return;
15683
15729
  event.preventDefault();
15684
15730
  // The default changeState is true, as this is commonly used for: navigation, etc.
@@ -15691,13 +15737,9 @@
15691
15737
  const link = target.closest('a[g-preload]');
15692
15738
  if (!link)
15693
15739
  return;
15694
- const href = link.getAttribute('href');
15695
- if (!href)
15696
- return;
15697
- const url = new URL(href, window.location.href);
15698
- if (url.origin !== window.location.origin)
15699
- return;
15700
- preload(url.toString());
15740
+ const url = eligibleAnchorUrl(link);
15741
+ if (url)
15742
+ preload(url.href);
15701
15743
  }
15702
15744
  function onSubmit(event) {
15703
15745
  if (event.defaultPrevented)
@@ -15850,7 +15892,7 @@
15850
15892
  portalCreate,
15851
15893
  portalDestroy,
15852
15894
  setCspNonce,
15853
- version: '0.5.5'
15895
+ version: '0.5.7'
15854
15896
  };
15855
15897
 
15856
15898
  setExpressionRuntime(cspExpressionRuntime);