Skip to content

Embeddable signal viewer route (phase 1 of #410) - #415

Merged
neuromechanist merged 35 commits into
stagingfrom
feature/issue-410-embed-viewer
Oct 5, 2026
Merged

neuromechanist merged 35 commits into
stagingfrom
feature/issue-410-embed-viewer

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds /dataset/<id>/embed, a chrome-free signal viewer that partner sites can put in an iframe, and makes it the only route another site may frame. The dataset page's viewer dialog gains an Embed control that copies the snippet. The dialog's orchestration moves into one shared module, src/lib/eeg-viewer/viewer-session.ts, which the dialog and the embed both drive, so a viewer feature is written once for both surfaces.

Refs #411, part of #410 (closing keywords do not fire on staging merges).

What changed

Shared viewer session. viewer-session.ts now owns the live instance and its supersession counter, opening a recording, navigate/step and the subject/task handlers, nav-control sync (labels, disabled ends, focus hand-off), the unsaved-annotation draft guard, settings transfer, neighbour prefetch, the units notice, ?view= resolution and URL sync, Copy link, and the new Embed control. Page-specific behavior comes in through hooks (isShowing, setTitle, present, onRelease, onDetach, onViewerOpen, mountOptions, fallbackActionHtml, onViewParamMiss, onRecordingShown, shareLink, embedSnippet), never a branch on "is this the embed". The dataset page keeps only its own parts: the inline tree row, Enlarge, the dialog open/close glue (including the corner-X veto), tree hydration and View data. ADR 0012 gets an update saying where its code now lives. The refactor is its own commit and was characterized in a browser before and after (gate 6).

Viewer options (viewer.ts, annotation-ui.ts). scopeOverlay appends a caller element into .eegv__scope on every mount (stamped data-eegv-overlay); the annotation layer's capture-phase pointerdown and click ignore events that start inside it, and the cursor readout treats its box as a no-readout zone so an overlay hidden while the readout shows stays reachable. fitHeight sizes the scope to what the host leaves after the other controls (floor 140 px), tracked by a second ResizeObserver that re-renders only when the fit moved and applies the height at once so a slow window read cannot leave the document overflowing; the default rule is unchanged. unavailableLink replaces the download link and the "expand arrow" hint, which mean nothing in an embed; the sentence is now the exported, tested unavailableMessageHtml.

Embed route (src/pages/dataset/[id]/embed.astro, src/layouts/Embed.astro). SSR mirrors the dataset page: ds* ids 301 to the on* embed keeping the query, the same landing and metadata helpers with the same 404/503/500 rules (no-store, with a sentence and a link in place of an empty body), the same ?v= selection and the same public Cache-Control. It never reads the session. The layout has global tokens and CSS, the favicon, noindex, a canonical to the dataset page and a pre-paint ?theme=light|dark bootstrap; no nav, footer, notices, cookie notice, assistant widget or Umami. The header (one line, two at 360 px) carries the recording name, EegViewerNav, Open on NEMAR and, last, a privacy link with PrivacyChoicesIcon from #414 named "Privacy: how NEMAR counts embedded views". The client is a thin shell over the session. The NEMAR mark sits bottom-right on the scope, at 0.55 opacity (1 on hover and focus), clear of the 22 px time axis, hidden while the cursor readout shows. Every outbound link opens a new tab on the serving origin. A ?view= miss, no viewable recordings, or an index that will not load shows a sentence and a link, never a blank frame.

Framing (src/middleware.ts). routeAllowsFraming matches /dataset/<id>/embed on the raw path (encoded spellings fail closed). That route gets frame-ancestors * and no X-Frame-Options; every other route keeps 'self' and SAMEORIGIN. applySecurityHeaders is the one place, so passthrough, cache HIT and cache MISS agree, and it deletes any XFO a cached response carried. A test walks every page file under src/pages/ and finds exactly one frameable page; tests pin 'unsafe-eval' on the embed route and, in host.test.ts, that it is a marketing route.

Edge cache (src/lib/edge-cache.ts). theme joins view in CLIENT_ONLY_QUERY_PARAMS. No route reads it server-side (grep of every searchParams read under src/).

Snippet (src/lib/embed.ts). Route matcher, ?theme= parser, embed and dataset-page URL builders, and embedSnippet with escaped attributes, in the shape #410 specifies. The dialog's Embed control builds it for the recording on screen, pinned to ?v= only when the page was. On clipboard failure it reveals a read-only, pre-selected textarea, hidden again on the next navigation.

Shared markup and CSS. The dialog's nav markup and styles move to EegViewerNav.astro; the viewer CSS moves verbatim (whitespace-insensitive diff is empty) from BidsTree.astro to src/styles/eeg-viewer.css, imported by BidsTree and the embed.

Docs. ADR 0023 (separate route, frame-ancestors * without an allowlist, no XFO, no session/notices/assistant widget/analytics, mark on the scope, one shared session, alternatives); indexed; AGENTS.md map; CHANGELOG [Unreleased] entries.

Review fixes

Every item from the two reviews of this PR is applied as its own commit; nothing was skipped.

  • Missing vs failed index (fetchZarrIndexOutcome): ok, absent (the index's 404) or error (network failure, another non-OK status, or a body parseZarrIndex rejects, now logged with the dataset id). fetchZarrIndex wraps it, so the dataset page is unchanged. The embed says "This dataset has no interactive recordings yet." for absent and keeps "right now" for error. Tested with real Response objects (a captured on000246 index, 404/403/500/503, a non-JSON body, a rejected index) and a refused loopback connection, no replaced fetch.
  • Throws never blank the frame: the embed shell catches start() (logs [embed] with the id, shows a notice and the dataset link); afterClaim runs inside mount's try.
  • Failed mounts are disposed: both session catches dispose through live.destroy ?? host._eegvCleanup before dropping the handle; the units notice, the viewer-open hook and neighbour prefetch run after the try, each logged on its own.
  • A failed navigation restores the chrome to the last recording that went live (shownPath/shownName): A, next (B in flight), next (C throws) lands back on A.
  • Late host children are budgeted: in fit mode a MutationObserver on the host refits when the units notice (or any sibling) arrives and observes its size from then on.
  • Debug context: console.warn("[embed]", { datasetId, version, view, reason }) in showNotice; { datasetId, path } on the [eeg-viewer] open-failed, navigation-failed and unavailable logs.
  • present returns a boolean; openRecording presents first and stops before releasing anything, setting the title or mounting when it fails. The dataset page's onRelease now closes the dialog only when the released instance is the one inside it.
  • Draft guard: only a throwing isPopoverOpen() fails open; a throwing focusPopover() is logged and the navigation is still refused.
  • Copy race: Copy link and Embed capture the recording path before awaiting the clipboard and write nothing if the visitor navigated meanwhile.
  • Unavailable wording: "may still be generating" only for a missing store (zarrita's NotFoundError, via isMissingStoreError); otherwise "The viewer could not load this recording." A retry control is Viewer: a Try again action when the first recording fails to open #416.
  • SSR fallbacks: a rejected resolveCanonical is logged with the id on the embed and the dataset page; a ?v= naming no published version is logged and the embed shows one ellipsized line, "Version X is not published; showing the latest, Y."
  • No-script: a <noscript><style> hides "Loading viewer…".
  • No spoofing on the frameable 404: the id is echoed only when it matches /^[A-Za-z0-9._-]{1,40}$/ (displayableDatasetId), in the body and the <title>; otherwise "NEMAR has no such dataset."
  • Privacy wording in Embed.astro, the embed and ADR 0023: no analytics script runs and no cookie is set; settings and annotations the visitor creates stay in their browser.
  • CSP pinned: a test asserts the embed's CSP equals the dataset page's once frame-ancestors * becomes 'self'. (No Map-backed cache test, as asked.)
  • Comments and docs: embed.ts no longer claims a test covers the inline theme bootstrap; ADR 0012's update heading drops its em-dash.
  • releaseEegViewer deleted; the inline open calls session.release().
  • One context builder: sessionContext(datasetId, version, zarr) in viewer-session.ts, used by the inline row, View data, ?view= and the embed, and unit tested; the dead zarrTokenForButton goes.

The fault-path checks above (items 2, 3, 4, 7 and the copy race) were run in Chromium and WebKit against the dev server by injecting a fault in the page (a throwing history.replaceState, analytics hook, 2d context or clipboard, or a removed dialog slot), since real data does not produce those failures on demand.

Decision gates

Measured against bun run dev (production backends) from a cross-site parent page on http://127.0.0.1:8080, with Playwright in Chromium and WebKit. Scripts and screenshots are in the session scratchpad (phase1/gates.ts, phase1/characterize-dialog.ts, phase1/gates/), not in the repository.

  • 1. Framed cross-site, no CSP or framing errors (Chromium, WebKit). Both load /dataset/on007753/embed?view=sub-05_task-BCCWJreading in an iframe on http://127.0.0.1:8080; the viewer mounts (one scope, title sub-05_task-BCCWJreading_eeg.vhdr) and the console has no CSP or framing messages. The only console errors are the dev server's Astro toolbar (504 Outdated Optimize Dep) and a 404 for a Zarr events chunk, both also present on origin/staging.
  • 1. Firefox. Not run: Playwright Firefox crashes at launch on this macOS; checked by the lead after the staging deploy.
  • 2. Every other route keeps 'self' and SAMEORIGIN. A unit test walks all 60 page files under src/pages/ (and trailing-slash spellings) through applySecurityHeaders and the middleware: exactly one frameable page, the embed. curl against the dev server: /, /dataset/on007753, /login, /settings, /upload send frame-ancestors 'self' and X-Frame-Options: SAMEORIGIN; /dataset/on007753/embed (with and without the trailing slash) sends frame-ancestors * and no XFO. Framing /dataset/on007753 from the parent is refused in both engines (Chromium: "violates the following Content Security Policy directive: frame-ancestors 'self'", frame at chrome-error://; WebKit: "Refused to load ... does not appear in the frame-ancestors directive").
  • 3. No document scroll at 360x480, 800x560, 1200x720. Both engines, both themes, sampled for two seconds after the viewer settles: overflow 0 px, and no render or scope resize while idle. Scope heights 182/352/476 px (Chromium) and 189/358/482 px (WebKit). At 360x400 the document scrolls by 38 px (Chromium) and 31 px (WebKit), which the gate allows below 420 px. The named fallback was not needed. Rerun after the review fixes, plus a recording with a units notice (on000246, MEG CTF, sub-0001_task-AEF_run-02, 16 channels kept the file's unit): overflow 0 px in both engines, both themes, at all three sizes (scope 155/343/467 px Chromium, 162/349/473 px WebKit). A line appended to the host after the viewer settles overflowed by 27 px before the refit fix and 0 after.
  • 4. The mark. Visible at opacity 0.55 with ?theme=light, ?theme=dark, and both prefers-color-scheme emulations without ?theme= (wordmark follows --color-fg: rgb(15, 23, 42) light, rgb(241, 245, 249) dark). Over the trace the cursor readout shows and the mark goes to opacity 0 with pointer-events: none; moving onto the mark clears the readout and brings it back at opacity 1. Its bottom edge sits 7 to 8 px above the time-axis band at all three sizes, inside the scope. A click opens http://localhost:4321/dataset/on007753?view=sub-05_task-BCCWJreading in a new tab. With annotate armed, a click on the mark opens the tab and places nothing (no popover, 0 events · 0 channel marks), while a click on the trace with the same armed tool does open the popover. Our own solid 2px focus outline shows on the mark, the header links, the privacy link and the dialog's Embed button, also under Chromium forcedColors: "active"; WebKit checked with Option+Tab, its tab-to-every-control key.
  • 5. ?view= resolves as on the dataset page. Exact sub-05_task-BCCWJreading, relaxed sub-05_task-nope and sub-5 all open sub-05_task-BCCWJreading_eeg.vhdr and rewrite ?view= to sub-05_task-BCCWJreading, as the dialog characterization records for the dataset page. ds007753 301s to /dataset/on007753/embed with the query (and ?theme=dark) intact. sub-99 shows "This embed asked for sub-99, but no recording in this dataset matches it." with a new-tab link to the dataset page. No ?view= opens the first recording in nav order (sub-01). Directory recordings mount: on004696 (iEEG MEF3 .mefd) and on000246 (MEG CTF .ds, ?view=sub-0001_task-AEF_run-02).
  • 6. The dataset page's viewer is unchanged. A Playwright characterization of the dialog on on007753, recorded on origin/staging before the refactor and replayed after it and again on the final branch (View data; exact, relaxed, zero-padded and missing ?view=; inline row to Enlarge and back with no remount; Enlarge, next, close ends the instance and collapses the row; prev/next and both dropdowns with labels, disabled ends and focus hand-off; Copy link and ?view= tracking, cleared on close; the draft guard refusing next and a subject pick and vetoing the corner X; fast next x3 leaving one live viewer) is identical. No mark on the dataset page (0 overlays) and the same height rule: dialog scope 540 px and inline scope 389 px at 1280x900, on origin/staging and on this branch.
  • New failure states (Chromium, WebKit, 800x560 and 360x480). on007406 (no Zarr copy, index 404) shows "This dataset has no interactive recordings yet." with the dataset link; /dataset/on007753/embed?view=sub-05_task-BCCWJreading&v=v9.9.9 shows "Version v9.9.9 is not published; showing the latest, v1.0.0." and mounts the viewer. Neither scrolls.
  • 7. bun run lint, bun run typecheck, bun run test, bun run build. All green.

Tests

bun run test: 2931 passed, 7 skipped (125 files); origin/staging has 2869, so this PR adds 62, covering embed.ts (including displayableDatasetId), fitScopeHeight, unavailableMessageHtml and isMissingStoreError, the session's pure navControlState, viewSpecForPath and sessionContext, the Zarr index outcome mapping, ?theme= in the cache key, the framing policy with the page-file walk and the embed-vs-page CSP comparison, and the embed route's host classification. Inputs are real on007753, on004696 and on000246 index paths and responses; no mocks. bun run typecheck: 0 errors, 0 warnings. The DOM orchestration is covered by the browser characterization and the gate scripts, rerun after the review fixes (gate 6 still identical to origin/staging).

Follow-ups

  • Firefox: not run here (see the gate notes); the lead checks it after the staging deploy.
  • The gates ran against the local dev server. Epic: embeddable signal viewer, edge-counted embed calls, and Your Privacy Choices #410's gates name test.nemar.org; they need repeating there after the merge deploys, including a framed cache HIT (the dev server's cache never answers HIT, so only the MISS and passthrough paths were exercised live; HIT shares applySecurityHeaders, which the unit tests cover).
  • The privacy link goes to /privacy (the docs privacy policy). Phase 5 adds the embed section; once it has an anchor, the link can point at it.
  • Phase 2 (edge counting) builds on the embed route's middleware branch.
  • A retry control for a recording the viewer could not load is Viewer: a Try again action when the first recording fails to open #416; this PR only changes the wording.

The .eegv and .eegv__* rules and .eegv-units-notice move out of
BidsTree.astro's global style block into src/styles/eeg-viewer.css,
which BidsTree.astro imports, so a page without a file tree can load
them (website#410). Biome reformatted whitespace only; a
whitespace-insensitive diff of the old block and the new file is empty.
Lint green.
The dialog's subject, task, prev and next markup and its scoped styles
move into EegViewerNav.astro so the embed route can render the same
controls. Data attributes are unchanged, so the dataset page script
needs no change. The dialog keeps its own copy of the .eegv-nav__btn
rules for the Copy link button, with a sync comment. Lint green.
mountEegViewer can append a caller-supplied element into .eegv__scope
on every mount, stamped data-eegv-overlay. The annotation layer's
capture-phase pointerdown and click handlers ignore events that start
inside it, so a click on the overlay never places an annotation, and
the cursor readout treats its box as a no-readout zone so an overlay
hidden while the readout shows can still be reached. The dataset page
passes no overlay. Unit tests and lint green; browser check comes with
the embed page.
With fitHeight the scope takes the height its host leaves after the
viewer's other controls, floored at 140 px, instead of
min(width/2, 540, 0.7 * innerHeight). A second ResizeObserver on the
host and the viewer root follows frame resizes and chrome that fills in
late, and re-renders only when the fit moved, so applying a height
cannot loop. Off by default; the dataset page's rule is unchanged.
fitScopeHeight is unit tested.
A new unavailableLink option replaces the fallback's download link and
the directory recording's expand-arrow hint, neither of which exists in
an embed. It renders escaped, in a new tab. The sentence moves into an
exported unavailableMessageHtml so the choice and the escaping are unit
tested; the dataset page output is unchanged. Tests and lint green.
src/lib/embed.ts holds the embed contract shared by the middleware, the
embed page and the dataset page's Embed control: the /dataset/<id>/embed
route matcher (raw path, so encoded spellings fail closed), the ?theme=
parser, embed and dataset page URL builders, the origin a snippet names,
and the iframe snippet with escaped attributes. Unit tested.
The dialog's orchestration moves out of the dataset page script into
src/lib/eeg-viewer/viewer-session.ts so the embed route can drive the
same code: the live instance and its supersession counter, opening a
recording, navigate and step, the subject/task/prev/next sync, the
draft guard, settings transfer, neighbour prefetch, the units notice,
?view= resolution and URL sync, and Copy link. Page-specific behavior
comes in through hooks. The page keeps the inline tree row, Enlarge,
and the dialog open/close glue.

Tested: a Playwright characterization of the dialog on on007753 (View
data, exact/relaxed/zero-padded/missing ?view=, inline to Enlarge and
back without a remount, Enlarge then next then close, prev/next and
both dropdowns with labels, disabled ends and focus hand-off, Copy link
and URL tracking, the draft guard on next, subject and the corner X,
fast next x3) gives identical results on origin/staging and after this
change. Pure pieces are unit tested; lint, typecheck and tests green.
ADR 0012 gets an update noting where its code now lives.
theme joins view in CLIENT_ONLY_QUERY_PARAMS, so every embedder's
?theme=light|dark shares one cached copy of the embed route. Safe
because no route reads it on the server: a grep of every searchParams
read under src/pages, src/layouts, src/components, src/lib and the
middleware finds none for theme, and the embed layout applies it in an
inline script before first paint. Unit tested.
A minimal document for the embed route: global tokens and CSS, the
favicon, robots noindex, a canonical link resolved like Base.astro's,
and an inline bootstrap that applies ?theme=light|dark before first
paint and otherwise leaves the system preference in charge. No nav,
footer, notices, cookie notice, assistant widget or Umami tracker. The
body is exactly the frame's height. Lint green; exercised with the embed
page.
A chrome-free page for partner iframes. SSR mirrors the dataset page:
ds* ids 301 to the on* embed with the query kept, landing and metadata
via the same helpers with the same 404/503/500 rules (no-store), the
same ?v= selection and public Cache-Control. Errors, an unpublished
dataset, a ?view= miss or no viewable recordings render a sentence and
a link, never a blank frame. The header carries the recording name,
EegViewerNav and Open on NEMAR; the NEMAR mark sits on the scope.

The client is a thin shell over the shared viewer session, which gains
mountOptions (fitHeight, the mark as scopeOverlay, an unavailable link
to the dataset page) and onRecordingShown (keeps every outbound link on
the recording on screen). Links open a new tab on the serving origin.

Tested in Chromium against bun run dev: at 360x480, 800x560 and
1200x720 the document does not scroll; lint and typecheck green.
routeAllowsFraming matches /dataset/<id>/embed only. That route gets
frame-ancestors * and no X-Frame-Options; every other route keeps
frame-ancestors 'self' and SAMEORIGIN. applySecurityHeaders is the one
place, so passthrough, cache HIT and cache MISS agree, and it deletes
any X-Frame-Options a cached response carried.

Tests walk every page file under src/pages through applySecurityHeaders
and the middleware and find exactly one frameable page; they pin
'unsafe-eval' on the embed route and, in host.test.ts, that it is a
marketing route. curl against bun run dev: the embed sends
frame-ancestors * without XFO; /, /dataset/on007753, /login, /settings
and /upload send 'self' and SAMEORIGIN. Tests and typecheck green.
Next to Copy link, Embed copies an iframe snippet for the recording on
screen: embedUrl on the marketing origin from a production host (this
deploy's origin elsewhere), pinned to ?v= only when the page was, and
the session's viewSpec. A refused clipboard reveals the snippet in a
read-only, pre-selected textarea, hidden again on the next navigation.
It shares the status live region and has its own focus outline.

Tested in Chromium and WebKit against bun run dev: the clipboard holds
the expected snippet; with clipboard-write denied the textarea shows,
focused and fully selected, and hides after next. The dialog
characterization still matches origin/staging exactly.
ADR 0023 records the separate chrome-free embed route, frame-ancestors *
with no allowlist and no X-Frame-Options there, the absent session,
notices, assistant widget (an exception to ADR 0018) and analytics, the
mark on the scope, and the shared viewer session; indexed in the
decisions README. AGENTS.md lists the new files; CHANGELOG.md gains the
Unreleased entries. Docs only.
Last in the header, the shared PrivacyChoicesIcon from #414 links to
/privacy on the serving origin, in a new tab. Its accessible name is a
statement, "Privacy: how NEMAR counts embedded views", since nothing can
be chosen inside an embed. Narrow-frame header spacing tightens so the
header stays two lines at 360 px. Measured in Chromium: no document
scroll at 360x480, 800x560 and 1200x720.
On a narrow host the status line is one line while a window loads and
two once the summary replaces it, so each render moved the fit and each
fit started a render. A fitHeight viewer now carries .eegv--fit, which
holds the status to one ellipsized line (full text in its title), and a
moved fit is applied to the scope at once instead of after any read in
flight, so a late legend or minimap no longer overflows the frame.

Tested in WebKit and Chromium at 360x480: no overflow sampled over two
seconds and no status or scope mutation once settled. Dataset page
untouched (the class is fit-only).
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

fetchZarrIndexOutcome returns ok, absent (the index's 404) or error (a
network failure, another non-OK status, or a body parseZarrIndex
rejects, which now logs with the dataset id). fetchZarrIndex wraps it,
so the dataset page is unchanged. The embed says "This dataset has no
interactive recordings yet." for absent and keeps "right now" for
error; the dead .catch is gone.

Tested: the mapping with real Response objects (a captured on000246
index, 404/403/500/503, a non-JSON body, a rejected index), a refused
loopback connection, and on007406 (no Zarr copy) in Chromium and WebKit
at 800x560 and 360x480.
The embed shell's start() rejection is now caught: it logs [embed] with
the dataset id and shows a notice with the dataset link. The session's
afterClaim hook moves inside mount's try, so a throwing hook ends in
the same failed outcome as a throwing mount.

Tested in Chromium and WebKit by making history.replaceState throw in
the page (an injected fault, ?view=sub-05_task-nope so the URL must be
rewritten): the notice and the link show and the console names
on007753.
When mount or navigate threw, the catch dropped the session's handle
without disposing what the failed mount had built; now both catches
dispose through live.destroy or the host's own cleanup first. The
post-success side effects (units notice, the viewer-open hook, neighbour
prefetch) run after the try, each logged on its own, so a throw there
no longer turns a working viewer into an unowned one behind a
"couldn't open" message. Logs carry { datasetId, path }.

Tested in Chromium and WebKit with injected faults: an analytics hook
that throws leaves the dialog's viewer live and navigable and Escape
disposes it; a 2d-context throw mid-navigation leaves no scope behind.
A failed navigation put the chrome back on the previous target, which
could itself have been mid-mount. The live record now tracks shownPath
and shownName, updated only when a mount goes live, and a failed
navigation restores to those.

Tested in Chromium and WebKit on the embed (on007753): from sub-01,
next (sub-02 in flight) then next (sub-03, an injected 2d-context
throw) leaves the title, the counter (1 of 41), the next label and
?view= on sub-01, and next from there opens sub-02.
In fit mode a sibling appended to the host after the first fit (the
session's units notice) resized neither the host nor the viewer root,
so nothing refit and the document could scroll by the notice's height.
A MutationObserver on the host's children now refits, and observes
each new child's size. The embed pads the notice to the viewer's edge
and, at 560 px and narrower, caps the nav selects at 5.5rem with
tighter header gaps, which keeps the header to two lines with a long
subject label.

Tested in Chromium and WebKit: a line appended to the host after the
viewer settles overflowed by 27 px before this and 0 after; on000246
(MEG, a real units notice) does not scroll at 360x480, 800x560 or
1200x720 in either theme.
The embed shell's showNotice logs one console.warn("[embed]", {
datasetId, version, view, reason }); the viewer's [eeg-viewer]
unavailable log carries { datasetId, path } (the session's open and
navigation failure logs already do, from the mount fix).

Tested in Chromium: a ?view= miss on on007753 and on007406's missing
index each log the expected object.
The present hook returns a boolean. openRecording presents the new host
first and stops, logging { datasetId, path }, before releasing the
current viewer, setting the title or mounting anything when it returns
false. Because the new host is now presented before the release, the
dataset page's onRelease closes the dialog only when the released
instance is the one inside it.

Tested in Chromium and WebKit: View data over an open inline row
presents sub-01 and collapses the row; with the dialog slot removed it
leaves the inline viewer live and the title unchanged. The dialog
characterization still matches origin/staging.
The unsaved-annotation guard failed open whenever anything threw,
including focusPopover after isPopoverOpen had already said a draft was
open, which let the navigation through and lost the draft. Now only a
throwing isPopoverOpen fails open; a throwing focusPopover is logged
and the navigation is still refused. The draft-guard scenarios of the
dialog characterization are unchanged.
Copy link and Embed capture the recording path before awaiting the
clipboard and, if the visitor navigated meanwhile, write neither the
status nor the fallback textarea, which would otherwise describe a
recording no longer on screen.

Tested in Chromium: with the clipboard write held pending, navigating
before it settles leaves the status empty and the textarea hidden; the
normal and refused-clipboard paths behave as before.
The unavailable sentence said the Zarr copy "may still be generating"
for every failed open. It now says that only when zarrita reports the
store missing (isMissingStoreError, its NotFoundError, which is what a
404 on the root metadata becomes) and otherwise "The viewer could not
load this recording." A recorded failure reason still wins. A retry
control is website#416, not built here.

Tested: unavailableMessageHtml for both cases, isMissingStoreError
against a real zarrita open of an empty in-memory store and against
other errors.
resolveCanonical(id).catch(() => null) on the dataset page swallowed a
rejected ds* to on* lookup without a trace. It now logs the id and the
error, and still serves the id as-is. Typecheck green.
The embed logs a rejected canonical lookup the same way the dataset page
now does. A ?v= that names no published version still falls back to the
latest, and now says so in a one-line, ellipsized note ("Version X is
not published; showing the latest, Y.") with a server-side warning.

Tested in Chromium and WebKit on on007753 with ?v=v9.9.9 at 800x560 and
360x480: the note shows, the viewer mounts, the document does not
scroll.
With scripting off, "Loading viewer…" stayed on screen beside the
noscript sentence forever. A <noscript><style> hides the placeholder
then, leaving only the sentence and its link.

Tested in Chromium and WebKit with JavaScript disabled: the placeholder
computes to display none and the noscript sentence shows; with
JavaScript on nothing changes.
The frameable not-found page printed the path segment verbatim ("NEMAR
has no dataset <id>.") and so did its <title>, which let any site put
its own sentence on a nemar.org page inside its frame. displayableDatasetId
admits /^[A-Za-z0-9._-]{1,40}$/; anything else reads "NEMAR has no
such dataset." and titles the page "NEMAR dataset". The meta
description follows the same rule.

Tested: unit tests for both sides of the rule; curl against the dev
server for on999999 (echoed) and two sentence-shaped paths (not
echoed in the body or the title).
"Nothing runs on the visitor's device" and "sets nothing on the
device" were wrong: the viewer keeps its nav order, preload settings
and annotations in browser storage. Embed.astro, the embed's privacy
link comment and ADR 0023 now say no analytics script runs and no
cookie is set; settings and annotations the visitor creates stay in
their browser. Phase 5 copies this into the privacy policy. Docs and
comments only.
The embed route's Content-Security-Policy must equal the dataset page's
once its frame-ancestors * is replaced by 'self', so framing stays the
only difference ADR 0023 makes. Tests green.
embed.ts no longer claims a test covers the inline theme bootstrap; it
names the other copy (the is:inline script in Embed.astro's head) and
says the two are kept in step by hand. ADR 0012's new heading drops its
em-dash. Comments and docs only.
The releaseEegViewer wrapper had one caller left and a comment naming
two; it is gone and the inline open calls session.release() itself,
with the comments that named the wrapper updated. No behavior change;
the dialog characterization is rerun after the next commit.
sessionContext(datasetId, version, zarr) in viewer-session.ts builds the
SessionContext for every page that opens a recording: the dataset page's
inline row, View data and ?view=, and the embed. It passes the Zarr
state through so its prefetched set stays shared with the tree rows,
and gives an empty list and the un-busted token without an index. The
now unused zarrTokenForButton goes.

Tested: unit tests on on007753 paths and the no-index case; the dialog
characterization still matches origin/staging; typecheck green.
Records under Changed that a Zarr copy that exists but will not load is
no longer described as still generating, on the dataset page and in the
embed. The shared session is not user-visible, so it gets no entry.
Also drops a stray blank line inside the Added list. Docs only.
@neuromechanist
neuromechanist merged commit 298674b into staging Oct 5, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-410-embed-viewer branch October 5, 2026 10:25
neuromechanist added a commit that referenced this pull request Oct 5, 2026
Re-review of #426: the embed's unknown-version note (and its log)
quoted the raw ?v= value, the same echo #426 closed for ?view=.
displayableVersion admits version tokens such as v1.0.1, and anything
else reads "That version". displayableViewParam now trims, as
parseViewSpec does, and says what it can and cannot rule out. The
changelog says where #415's code moved from, and ADR 0024 and the flag
comment describe the widened catch.

Tested: lint, typecheck, unit tests.
neuromechanist added a commit that referenced this pull request Oct 5, 2026
* Quote ?view= in notices only when it is a name

Release review of #424: the embed's and the dataset page's "no
recording matches" notices quoted the raw ?view= value, so anyone
writing a link (or framing the embed) could put their own sentence on a
nemar.org page. displayableViewParam quotes values shaped like entity
strings, filenames or BIDS paths and says "a recording" otherwise, the
same guard displayableDatasetId gives the path id.

Tested: recording-nav tests (90 passed), including real view values and
free-text refusals.

* Count embed calls with the point built in the try

Release review of #424: embedCallPoint ran outside countEmbedCall's
try. No input found makes it throw, but a counter must never break the
response it counts, so building the point now sits inside the same
catch as the write, and the log names the dataset when there is one.

Tested: middleware tests (83 passed).

* docs: changelog corrections from the release review

- the private handoff's 501 keys on the API base, not production;
- the page's own responses carry no-store/no-referrer/noindex, a
  cross-host redirect only no-store;
- add the shared viewer session (#415) and the ?theme= cache key;
- add the ?view= quoting fix.

* Quote ?v= only when it is a version; review nits

Re-review of #426: the embed's unknown-version note (and its log)
quoted the raw ?v= value, the same echo #426 closed for ?view=.
displayableVersion admits version tokens such as v1.0.1, and anything
else reads "That version". displayableViewParam now trims, as
parseViewSpec does, and says what it can and cannot rule out. The
changelog says where #415's code moved from, and ADR 0024 and the flag
comment describe the widened catch.

Tested: lint, typecheck, unit tests.

* test: format the displayableVersion cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant