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.
@@ -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
  */
@@ -2797,7 +2797,8 @@ function syncBooleanProperty(element, attrName, value) {
2797
2797
  const propertyName = booleanPropertyNames[attrName] || attrName;
2798
2798
  if (propertyName in element) {
2799
2799
  try {
2800
- element[propertyName] = value;
2800
+ if (element[propertyName] !== value)
2801
+ element[propertyName] = value;
2801
2802
  }
2802
2803
  catch {
2803
2804
  // Some reflected DOM properties are read-only in older engines.
@@ -2828,9 +2829,14 @@ function applyAttributeBinding(element, rawAttrName, value) {
2828
2829
  }
2829
2830
  const stringValue = String(value);
2830
2831
  if (attrName === 'value' && 'value' in element) {
2831
- element.value = stringValue;
2832
+ // Compare the live control, not a cached expression: user edits and
2833
+ // external DOM changes still need reconciliation on the next update.
2834
+ if (element.value !== stringValue) {
2835
+ element.value = stringValue;
2836
+ }
2832
2837
  }
2833
- element.setAttribute(attrName, stringValue);
2838
+ if (element.getAttribute(attrName) !== stringValue)
2839
+ element.setAttribute(attrName, stringValue);
2834
2840
  }
2835
2841
  function boundAttributes(element) {
2836
2842
  return Array.from(element.attributes).filter(attribute => attribute.name.startsWith(':'));
@@ -8152,7 +8158,6 @@ function refresh(options = {}) {
8152
8158
  }
8153
8159
  const snapshots = new Map();
8154
8160
  const preloadCache = new Map();
8155
- const preloadControllers = new Map();
8156
8161
  const scrollPositions = new Map();
8157
8162
  const historyFragments = new Map();
8158
8163
  let routerStarted = false;
@@ -8472,6 +8477,15 @@ function buildRequest(opts) {
8472
8477
  }
8473
8478
  return { finalUrl: url.toString(), init };
8474
8479
  }
8480
+ function discardPreload(key) {
8481
+ const entry = preloadCache.get(key);
8482
+ preloadCache.delete(key);
8483
+ entry?.controller.abort();
8484
+ }
8485
+ function clearPreloads() {
8486
+ for (const key of preloadCache.keys())
8487
+ discardPreload(key);
8488
+ }
8475
8489
  function preload(url) {
8476
8490
  const cacheKey = canonicalUrl(url, true);
8477
8491
  if (preloadCache.has(cacheKey))
@@ -8486,11 +8500,11 @@ function preload(url) {
8486
8500
  signal: controller.signal,
8487
8501
  mode: 'same-origin'
8488
8502
  });
8489
- preloadCache.set(cacheKey, request);
8490
- preloadControllers.set(cacheKey, controller);
8503
+ const entry = { request, controller };
8504
+ preloadCache.set(cacheKey, entry);
8491
8505
  request.catch(() => {
8492
- preloadCache.delete(cacheKey);
8493
- preloadControllers.delete(cacheKey);
8506
+ if (preloadCache.get(cacheKey) === entry)
8507
+ preloadCache.delete(cacheKey);
8494
8508
  });
8495
8509
  }
8496
8510
  async function updateHead(fromDoc, signal, currentBaseUrl) {
@@ -8669,20 +8683,21 @@ async function navigateRequest(opts) {
8669
8683
  else {
8670
8684
  // Check preload cache if GET
8671
8685
  const preloadKey = canonicalUrl(finalUrl, true);
8672
- if (opts.fresh) {
8673
- preloadControllers.get(preloadKey)?.abort();
8674
- preloadControllers.delete(preloadKey);
8675
- preloadCache.delete(preloadKey);
8676
- }
8677
- if (!opts.fresh && opts.method.toUpperCase() === 'GET' && preloadCache.has(preloadKey)) {
8686
+ if (opts.fresh)
8687
+ discardPreload(preloadKey);
8688
+ const entry = init.method === 'GET' ? preloadCache.get(preloadKey) : undefined;
8689
+ if (entry) {
8678
8690
  log('[GyosRouter] using preload cache for', finalUrl);
8691
+ const signal = transaction.controller.signal;
8692
+ const discard = () => {
8693
+ if (preloadCache.get(preloadKey) === entry)
8694
+ discardPreload(preloadKey);
8695
+ };
8696
+ signal.addEventListener('abort', discard, { once: true });
8679
8697
  try {
8680
- response = await waitForNavigation(preloadCache.get(preloadKey), transaction.controller.signal);
8698
+ response = await waitForNavigation(entry.request, signal);
8681
8699
  }
8682
8700
  catch (error) {
8683
- preloadCache.delete(preloadKey);
8684
- preloadControllers.get(preloadKey)?.abort();
8685
- preloadControllers.delete(preloadKey);
8686
8701
  if (error.name === 'AbortError')
8687
8702
  throw error;
8688
8703
  assertActiveNavigation(transaction);
@@ -8690,8 +8705,11 @@ async function navigateRequest(opts) {
8690
8705
  fallback(finalUrl, true);
8691
8706
  return;
8692
8707
  }
8693
- preloadCache.delete(preloadKey); // consume cache
8694
- preloadControllers.delete(preloadKey);
8708
+ finally {
8709
+ signal.removeEventListener('abort', discard);
8710
+ if (preloadCache.get(preloadKey) === entry)
8711
+ preloadCache.delete(preloadKey);
8712
+ }
8695
8713
  }
8696
8714
  else {
8697
8715
  try {
@@ -8700,6 +8718,9 @@ async function navigateRequest(opts) {
8700
8718
  transaction.interval = setInterval(setRand, 300);
8701
8719
  response = await fetch(finalUrl, init);
8702
8720
  assertActiveNavigation(transaction);
8721
+ // A successful write can change HTML at any URL, including after a redirect.
8722
+ if (response.ok && init.method !== 'GET')
8723
+ clearPreloads();
8703
8724
  // Update progress to rand 70 - 80% after fetch
8704
8725
  progressBar?.setProgress(Math.random() * 10 + 70);
8705
8726
  if (transaction.interval)
@@ -8839,6 +8860,15 @@ async function navigateRequest(opts) {
8839
8860
  // The global outlet is also the incoming layout root. Keep its node for
8840
8861
  // inner swaps, but update attributes such as g-scope and layout classes.
8841
8862
  try {
8863
+ if (syncDocumentAttributes && !document.querySelector('base[href]')) {
8864
+ document.head.querySelectorAll('base[target]').forEach(base => base.remove());
8865
+ const baseTarget = doc.head.querySelector('base[target]')?.getAttribute('target');
8866
+ if (baseTarget != null) {
8867
+ const base = document.createElement('base');
8868
+ base.target = baseTarget;
8869
+ document.head.prepend(base);
8870
+ }
8871
+ }
8842
8872
  target = await performSwap(target, src, swapMode, {
8843
8873
  syncRootAttributes: isFullOutletNavigation,
8844
8874
  signal: transaction.controller.signal,
@@ -8964,10 +8994,39 @@ async function navigateRequest(opts) {
8964
8994
  opts.onEnd?.({ ...context });
8965
8995
  }
8966
8996
  }
8967
- function shouldBoost(el) {
8968
- if (el.closest('[g-no-boost]'))
8969
- return false;
8970
- return el.hasAttribute('g-boost') || hasGlobalBoost();
8997
+ function eligibleAnchorUrl(link) {
8998
+ if (!(link instanceof HTMLAnchorElement) || !link.getAttribute('href')
8999
+ || link.hasAttribute('download') || link.closest('[g-no-boost]'))
9000
+ return null;
9001
+ const target = link.getAttribute('target') ?? document.querySelector('base[target]')?.getAttribute('target');
9002
+ if (target && target.toLowerCase() !== '_self')
9003
+ return null;
9004
+ let url;
9005
+ try {
9006
+ url = new URL(link.href);
9007
+ }
9008
+ catch {
9009
+ return null;
9010
+ }
9011
+ if (!['http:', 'https:'].includes(url.protocol) || url.origin !== location.origin
9012
+ || url.username || url.password)
9013
+ return null;
9014
+ // URL.hash is empty for both an absent fragment and a trailing "#".
9015
+ if (url.href.includes('#') && canonicalUrl(url.href) === canonicalUrl(location.href))
9016
+ return null;
9017
+ // A page visit would need to remove the outgoing base before inserting
9018
+ // relative resources. Let the browser switch documents and enforce base-uri.
9019
+ if (document.querySelector('base[href]') && !link.hasAttribute('g-current-head')
9020
+ && !['append', 'prepend'].includes(link.getAttribute('g-swap')?.toLowerCase() || '')) {
9021
+ try {
9022
+ if (resolveTarget(link) === findGlobalOutlet())
9023
+ return null;
9024
+ }
9025
+ catch {
9026
+ return null;
9027
+ }
9028
+ }
9029
+ return url;
8971
9030
  }
8972
9031
  function onClickRouter(element) {
8973
9032
  log('[GyosRouter] g-router-link clicked');
@@ -9021,23 +9080,10 @@ function onClick(event) {
9021
9080
  return;
9022
9081
  }
9023
9082
  const link = target.closest('a');
9024
- if (!link)
9083
+ if (!link || !(link.hasAttribute('g-boost') || hasGlobalBoost()))
9025
9084
  return;
9026
- const href = link.getAttribute('href');
9027
- if (!href)
9028
- return;
9029
- const url = new URL(href, window.location.href);
9030
- if (url.origin !== window.location.origin)
9031
- return;
9032
- if (url.hash && canonicalUrl(url.href) === canonicalUrl(window.location.href))
9033
- return;
9034
- if (link.closest('[g-no-boost]'))
9035
- return;
9036
- if (link.hasAttribute('download'))
9037
- return;
9038
- if (link.getAttribute('target') && link.getAttribute('target') !== '_self')
9039
- return;
9040
- if (!shouldBoost(link))
9085
+ const url = eligibleAnchorUrl(link);
9086
+ if (!url)
9041
9087
  return;
9042
9088
  event.preventDefault();
9043
9089
  // The default changeState is true, as this is commonly used for: navigation, etc.
@@ -9050,13 +9096,9 @@ function onMouseOverCapture(event) {
9050
9096
  const link = target.closest('a[g-preload]');
9051
9097
  if (!link)
9052
9098
  return;
9053
- const href = link.getAttribute('href');
9054
- if (!href)
9055
- return;
9056
- const url = new URL(href, window.location.href);
9057
- if (url.origin !== window.location.origin)
9058
- return;
9059
- preload(url.toString());
9099
+ const url = eligibleAnchorUrl(link);
9100
+ if (url)
9101
+ preload(url.href);
9060
9102
  }
9061
9103
  function onSubmit(event) {
9062
9104
  if (event.defaultPrevented)
@@ -9209,7 +9251,7 @@ const Gyos = {
9209
9251
  portalCreate,
9210
9252
  portalDestroy,
9211
9253
  setCspNonce,
9212
- version: '0.5.5'
9254
+ version: '0.5.7'
9213
9255
  };
9214
9256
 
9215
9257
  // This file was generated. Do not modify manually!