@wcstack/router 4.21.0 → 4.23.0

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.esm.js CHANGED
@@ -78,7 +78,7 @@ function setConfig(partialConfig) {
78
78
  }
79
79
 
80
80
  var name = "@wcstack/router";
81
- var version = "4.21.0";
81
+ var version = "4.23.0";
82
82
  var pkg = {
83
83
  name: name,
84
84
  version: version};
@@ -1639,10 +1639,19 @@ function describeImportFailure(error, firstError, cspBlocked) {
1639
1639
  `Guard scripts are inline-only and are evaluated through a blob: URL: ` +
1640
1640
  `give the page's nonce to the <script> that loads @wcstack/router, or allow blob: in script-src. See ${CSP_GUIDE}`;
1641
1641
  }
1642
- return `loadGuardHandler: failed to import guard script. ` +
1642
+ const detail = `loadGuardHandler: failed to import guard script. ` +
1643
1643
  `data: URL error: ${error?.message ?? String(error)}` +
1644
- (firstError ? `. Blob URL error: ${firstError?.message ?? String(firstError)}` : '') +
1645
- `. If this page sets a Content-Security-Policy, see ${CSP_GUIDE}`;
1644
+ (firstError ? `. Blob URL error: ${firstError?.message ?? String(firstError)}` : '');
1645
+ // 解決できない import(Chromium "Failed to resolve module specifier"、Firefox "… specifier …"、
1646
+ // WebKit "does not resolve"): blob: URL が基準なので相対パスは解決できない。CSP は関係しない
1647
+ // (docs/seam-apps.md、ekiden-entry。state のインラインと同じ — community-hall)
1648
+ if (/specifier|does not resolve/i.test(detail)) {
1649
+ return `${detail}. A guard <script> is evaluated from a blob: URL, against which a relative or ` +
1650
+ `root-relative import ("./x.js", "/js/x.js") does not resolve: import a full URL inside the guard function — ` +
1651
+ `await import(new URL("/js/x.js", location.href).href) — or a name the page's import map gives ` +
1652
+ `({ "imports": { "@app/": "/js/" } }).`;
1653
+ }
1654
+ return `${detail}. If this page sets a Content-Security-Policy, see ${CSP_GUIDE}`;
1646
1655
  }
1647
1656
  async function importModule(script, route) {
1648
1657
  let scriptModule = null;
@@ -2560,10 +2569,14 @@ async function showRouteContent(routerNode, matchResult, lastRoutes, beforeChang
2560
2569
  placeRoute(route);
2561
2570
  }
2562
2571
  moved ||= again;
2563
- // 挿入の後。初回描画(lastRoutes が空)の内容は state のバインド構築時に
2564
- // document に居るので、そこは binder に渡す必要も報告する必要も無い。
2565
- // `bind()` 自体は冪等なので渡しても壊れないが、渡さないほうが安い。
2566
- if (previous.length > 0 && !again) {
2572
+ // 挿入の後。出ているルートが無いところへ置く内容(初回描画、どのルートにも
2573
+ // 当たらなかった後の最初のルート)は、binder がまだ居なければ渡さない: state の
2574
+ // 最初の走査がそのとき document に居るものを拾うので、渡す必要も報告する必要も無い。
2575
+ // binder がもう居るなら、その走査は済んでいるかもしれない — 時間のかかるガード
2576
+ // (`await import()`)がページを読み込むナビゲーションをリダイレクトすると、行き先の
2577
+ // 内容は走査の後に置かれ、何も束縛されなかった(docs/seam-apps.md、ekiden-entry)。
2578
+ // `bind()` は冪等なので、走査に間に合っていた分を渡しても壊れない。
2579
+ if (!again && (previous.length > 0 || getBinder() !== null)) {
2567
2580
  bindRouteContent(route);
2568
2581
  }
2569
2582
  }