@volter/world-console 3.0.7 → 3.0.8

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.
@@ -1771,13 +1771,26 @@ function Compare({ name, token, frame, onClose, reads }: { name: string; token:
1771
1771
  const o = httpOrigin(b.origin);
1772
1772
  if (!o) { setBefore({ state: 'none', why: 'This World shows sites only at its own local address.' }); return; }
1773
1773
  // a site at the copy's own address, framed; a vendor's page in the copy is behind the copy's session, which opens
1774
- // only on the copy's own pages (another site's frame is refused it), so it opens as a page of its own: the copy's
1775
- // hand-off page (served-world, `session/hand-off`) opens the session from the read token, then goes to the page
1774
+ // only on the copy's own pages (another site's frame is refused it): this World shows it instead, or, on a host
1775
+ // that cannot, the copy's hand-off page (served-world, `session/hand-off`) opens it as a page of its own
1776
1776
  if ('site' in shown) { const u = new URL(frame.url); setBefore({ state: 'ok', url: `${o.protocol}//${u.hostname}.${o.host}${u.pathname}${u.search}`, at }); return; }
1777
+ // shown by this World beside its own page, as a branch of it (its `copies` door), where its host holds the copy;
1778
+ // else opened at the copy's own address
1779
+ const id = b.name.slice(b.name.indexOf('/') + 1);
1780
+ const beside = `${WORLDS}/-/${name}/copies/${id}/${frame.vendor}${shown.screen}`;
1781
+ // the copy's own answer may be a 404 page (an account not there yet); the door's refusals are not
1782
+ const here = await fetch(beside, { method: 'HEAD', credentials: 'same-origin' }).then((r) => ![401, 403, 501, 503].includes(r.status), () => false);
1783
+ if (closed) return;
1784
+ if (here) { setBefore({ state: 'ok', url: beside, at }); return; }
1777
1785
  if (!b.readToken) { setBefore({ state: 'none', why: 'The copy of the World gave no read token to open its pages with.' }); return; }
1778
1786
  setBefore({ state: 'ok', url: `${o.origin}/-/${b.name}/session/hand-off#${new URLSearchParams({ token: b.readToken, land: `/${b.name}/${frame.vendor}${shown.screen}` }).toString()}`, at, opens: true });
1779
1787
  })(), 500);
1780
- return () => { closed = true; clearTimeout(wait); if (made) void door(token, `/-/${name}/branches/${made}`, { method: 'DELETE' }).catch(() => null); };
1788
+ // the copy goes with the comparison, and with the page: a reload or a closed tab runs no cleanup of its own
1789
+ const drop = (): void => { if (made) void door(token, `/-/${name}/branches/${made}`, { method: 'DELETE', keepalive: true }).catch(() => null); made = null; };
1790
+ // a page kept for back and forward keeps its copy: it may be shown again
1791
+ const left = (e: PageTransitionEvent): void => { if (!e.persisted) drop(); };
1792
+ window.addEventListener('pagehide', left);
1793
+ return () => { closed = true; clearTimeout(wait); window.removeEventListener('pagehide', left); drop(); };
1781
1794
  }, [name, token, frame.vendor, frame.id, frame.since]);
1782
1795
  const now = frameUrl(name, frame);
1783
1796
  return (