@brust/runtime-dom 2.0.0-alpha.34 → 2.0.0-alpha.36

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/nav/nav.ts +6 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brust/runtime-dom",
3
- "version": "2.0.0-alpha.34",
3
+ "version": "2.0.0-alpha.36",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
package/src/nav/nav.ts CHANGED
@@ -24,6 +24,10 @@ export function boot(load: Load = (u) => import(/* @vite-ignore */ u)): () => vo
24
24
  const g = globalThis as { [KEY]?: NavBridge }
25
25
  const build = document.querySelector(NAV)?.getAttribute('data-brust-build')
26
26
  if (g[KEY] || build == null) return () => {}
27
+ // F495: an app mounted under `base_path` navigates inside its own subtree only; a path outside it belongs to another app
28
+ // on the same origin, so a click or `navigate()` there is a full load (never a swapped fetch).
29
+ const base = document.querySelector(NAV)?.getAttribute('data-brust-base') ?? ''
30
+ const inBase = (path: string) => !base || path === base || path.startsWith(base + '/')
27
31
  const off = new AbortController()
28
32
  const on = (t: EventTarget, type: string, h: (e: any) => void, capture?: boolean) =>
29
33
  t.addEventListener(type, h, { capture, passive: type === 'touchstart', signal: off.signal })
@@ -117,7 +121,7 @@ export function boot(load: Load = (u) => import(/* @vite-ignore */ u)): () => vo
117
121
  if (href == null || a!.hasAttribute('download') || (a!.getAttribute('target') || '_self').toLowerCase() !== '_self' || a!.closest('[data-brust-reload]')) return null
118
122
  let u: URL
119
123
  try { u = new URL(href, document.baseURI) } catch { return null }
120
- if (u.origin !== location.origin || !/^https?:$/.test(u.protocol) || (u.href.includes('#') && sameDoc(u.href, location.href))) return null
124
+ if (u.origin !== location.origin || !/^https?:$/.test(u.protocol) || !inBase(u.pathname) || (u.href.includes('#') && sameDoc(u.href, location.href))) return null
121
125
  return [a!, u.href]
122
126
  }
123
127
 
@@ -253,7 +257,7 @@ export function boot(load: Load = (u) => import(/* @vite-ignore */ u)): () => vo
253
257
 
254
258
  const navigate = (u: string, o?: { replace?: boolean }): Promise<void> => {
255
259
  const url = new URL(u, location.href).href
256
- if (url.startsWith(location.origin + '/') && !document.body.closest('[data-brust-reload]') && !(url.includes('#') && sameDoc(url, location.href)))
260
+ if (url.startsWith(location.origin + '/') && inBase(new URL(url).pathname) && !document.body.closest('[data-brust-reload]') && !(url.includes('#') && sameDoc(url, location.href)))
257
261
  return go(url, 'navigate', ++seq, !!o?.replace || sameDoc(url, location.href))
258
262
  location[o?.replace ? 'replace' : 'assign'](url)
259
263
  return Promise.resolve()