Skip to content

fix(preview): a translations session should not inert the widget it is previewing #211

Closed

Description

@Ardnived

Summary

A translator previewing sy-atlas-translations gets a widget where nothing is clickable, so they cannot reach the screen the string they are editing appears on.

SahajCloud points that panel at the atlas root with a scope parameter (src/globals/SahajAtlasTranslations/SahajAtlasTranslations.ts):

{ATLAS}/?locale=<code>&live-preview=<token>&scope=sy-atlas-translations

The widget verifies the token, opens a session — and then applies the document guards to it, because it never reads scope.

What actually happens

LivePreviewController runs both session-wide hooks before it resolves what is being previewed (src/components/live-preview/LivePreviewController.tsx):

export function LivePreviewController() {
  useLivePreviewLinkGuard()        // every <a> goes inert
  usePinnedLivePreviewQueries()    // ['event'] / ['region'] pinned to staleTime: Infinity
  …
  if (!target) return null         // ← the document check happens here, too late
}

Both are right for a document session: the link guard keeps the panel from navigating away from the document being edited, and the pinned defaults protect a live-overlaid doc from being refetched out from under the edit.

Neither is right for a translations session. There is no document to navigate away from, and no ['event']/['region'] overlay to protect. The guards only take away the navigation the translator needs.

The underlying gap: scope is unread

src/config/live-preview/protocol.ts's LivePreviewSession is { active, token, collection, id }. There is no scope field, and readLivePreviewParams does not look for one — so the parameter the CMS sends rides in the URL unused.

⚠ WeMeditateWeb already models this, and the two consumers should agree. Its LivePreviewState is { active, scope }, readLivePreviewScope parses a closed set, and useDocumentPreviewActive() is active && scope === null — which is exactly the distinction missing here. See lib/live-preview/protocol.ts and session.ts in that repo.

Second-order: a scoped session still drafts everything

applyRequestContext (src/config/api/client.ts) adds draft=true to every request whenever the session is active. So a translations preview also puts events and regions into draft mode.

It is why the translations criterion in #206 passes at all today — drafts arrive incidentally. But it means a translator checking their strings sees them on top of whatever unsaved event and region drafts happen to exist, rather than on published content. WeMeditateWeb scopes this deliberately: "a page preview must not hand drafts to the translations read, and a translations preview must leave the page itself published."

Approach

  • Add scope to LivePreviewSession and parse it in readLivePreviewParams, as a closed set ('sy-atlas-translations'), unrecognised values falling back to null. Mirror WeMeditateWeb's names.
  • Move useLivePreviewLinkGuard and usePinnedLivePreviewQueries behind the document check, or gate them on scope === null.
  • Decide whether draft=true should be scoped too, or stay session-wide. Scoping it is more correct and a wider change — it may deserve splitting out.
  • Landing each tab on its own view is a separate door from the guards, and reaches four of the five unreachable tabs on its own. See "A resolved target" below.

Why a target per tab does not replace this

SahajCloud already repoints the panel per tab (previewTargetField), and search, filters and calendar declare a path. Those three tabs need no clicking, and targeting is the right mechanism for them.

It cannot cover the rest. A PreviewTarget is JSON, never a function (src/fields/previewTargetField.ts), and the global's livePreview.url reads locale and never data, so a target can only ever name a fixed path. The remaining views are keyed by a document or by layout (resolveStack, src/lib/shape/path.ts):

  • event is /<region>/<id>, registration is <event>/register, share is <event>/share. Each needs a live event id, which expires.
  • online is <region>/online, so it needs a region that has online events.
  • compact renders only when the embed box is too small, measured at mount (src/lib/slot-decision.ts). No parameter asks for it.

Those tabs are reachable only by clicking, which is exactly what the link guard inerts.

A resolved target reaches four of those five

A fixed path cannot name them. A path the widget resolves can, and it needs no CMS code: composeTargetUrl merges a target's params over the default URL, so a tab declares "preview": { "params": { "view": "event" } } in translationsSchema.json and nothing else changes on that side.

The widget then resolves view at boot, inside a verified session only, into a real path — eventsQuery (src/config/api/index.ts:55) picks the soonest published event for event, registration and share, and a region carrying online events for online. Because the document is chosen at render, it cannot expire the way a hard-coded id would.

Two alternatives were weighed and rejected:

  • Pick the id server-side in livePreview.url. It costs a database read on every resolve, and the id still goes stale mid-session.
  • A target per key rather than per tab. Not available: previewTargetField is tab-level only, because a collapsed collapsible still mounts its fields.

compact stays unreachable by any link. It is measured at mount, and this repo deliberately offers no override parameter — an open decision, not a design yet.

Acceptance criteria

  • A session opened with scope=sy-atlas-translations leaves every in-widget link live, and pins no query defaults.
  • A document session (an event or region path) keeps both guards exactly as they are today.
  • An unrecognised scope value behaves as an unscoped document session, never as an error.
  • A saved-but-unpublished translations draft still renders, on any view path.

Verification

  • pnpm lint && pnpm typecheck && pnpm test:run && pnpm build && pnpm size — each new assertion watched failing against today's behaviour first (docs/testing.md).
  • /admin → Sahaj Atlas → Translations → any tab: navigate inside the panel and confirm the widget still responds.
  • The same panel on an event path: confirm links are still inert.

Context

Split out of #206 while closing it. #206 listed "a document-less session renders no PreviewFallback, no link guard and no pinned query defaults" as an acceptance criterion; PR #208 delivered the first (PreviewFallback is gone) and not the other two. Everything else in #206 shipped, so this is the remainder rather than a reopening.

Activity

  1. added
    proposal
    on Sep 16, 2026
  2. Ardnived commented on Sep 17, 2026

    @Ardnived
    ContributorAuthor

    @sydevs-bot Answer: Why do translation previews need to be able to navigate? In theory SahajCloud already has a mechanism to land each tab on the correct page, which if configured correctly will be more reliable than the user navigating around.

  3. added
    bot:working
    and removed
    proposal
    on Sep 17, 2026
  4. sydevs-bot commented on Sep 17, 2026

    @sydevs-bot
    Contributor

    🤖 no session running

    recent dispatches
    • 17:05Z implement · attempt 1 · session · done
    • 17:05Z implement · attempt 1 · session
    • 00:50Z answer · attempt 1 · session · done
    • 00:50Z answer · attempt 1 · session
    • 00:42Z answer · attempt 1 · session · done

    Written by the sydevs dispatcher. Sessions never edit this comment.

  5. moved this from Proposed to Revising in SYDevelopers Technical Roadmapon Sep 17, 2026
  6. sydevs-bot commented on Sep 17, 2026

    @sydevs-bot
    Contributor

    Three tabs already use targets. Five name a view no static path can reach.

    A PreviewTarget is JSON, never a function (src/fields/previewTargetField.ts:7), and the global's url reads locale, never data. So it can only name a fixed path. search, filters and calendar declare one, and those tabs need no clicking.

    The rest are keyed by a document or by layout (src/lib/shape/path.ts:274):

    • event is /<region>/<id>, registration is <event>/register, share is <event>/share. Each needs a live event id, which expires.
    • online is <region>/online, so it needs a region that has online events.
    • compact renders only when the box is too small, measured at mount (src/lib/slot-decision.ts).

    Those five are reachable only by clicking, and the guard inerts every <a> but a #hash.

    Recorded under Approach in the body.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  7. added and removed
    bot:working
    on Sep 17, 2026
  8. Ardnived commented on Sep 17, 2026

    @Ardnived
    ContributorAuthor

    @sydevs-bot Research possible alternative solutions instead of removing the restriction on clicks, how can we create an actual usable preview link that goes directly to showing the place where the translations are used?

  9. added
    bot:working
    and removed on Sep 17, 2026
  10. sydevs-bot commented on Sep 17, 2026

    @sydevs-bot
    Contributor

    The best link-based option is a view param the widget resolves, not a static path.

    composeTargetUrl already merges a target's params over the default URL, so "preview": { "params": { "view": "event" } } in translationsSchema.json needs no CMS code. At boot, inside a verified session, the widget swaps view=event for a real path built from eventsQuery (src/config/api/index.ts:55) — the soonest published event. Same for registration, share and online. The target stays JSON, and the id is picked at render, so it cannot expire.

    Rejected: picking the id server-side in livePreview.url (a database read on every resolve, and it goes stale mid-session), and a per-key target (previewTargetField is tab-level only).

    compact still has no link. It is measured at mount (src/lib/slot-decision.ts), and this repo refuses an override parameter by design. That one needs your call.

    Recorded under Approach. The link guard question is now independent of it.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  11. added and removed
    bot:working
    on Sep 17, 2026
  12. Ardnived commented on Sep 18, 2026

    @Ardnived
    ContributorAuthor

    @sydevs-bot implement

  13. added
    bot:working
    and removed on Sep 18, 2026
  14. moved this from Revising to Approved in SYDevelopers Technical Roadmapon Sep 18, 2026
  15. removed
    bot:working
    on Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions