Skip to content

fix(preview): live-reload DocumentArtefact routes, pin doc page width - #191

Open
ThatScalaGuy wants to merge 1 commit into
mainfrom
fix/doc-preview-live-reload
Open

fix(preview): live-reload DocumentArtefact routes, pin doc page width#191
ThatScalaGuy wants to merge 1 commit into
mainfrom
fix/doc-preview-live-reload

Conversation

@ThatScalaGuy

Copy link
Copy Markdown
Contributor

The preview never pushed content updates to /doc/* routes. The doc loop in refresh.Run only swapped the static route, so editing a markdown source left the open browser tab stale, every refresh showed a false "Refresh failed" pill while a doc route was open, and GET /__preview/context?path=/doc/… returned 404 for the whole session.

Changes:

  • The doc loop now broadcasts the rendered document like the report loop does. swapContext on the client already extracts the bn-context from a full page, so the existing morph machinery works unchanged — long documents keep their scroll position while editing.
  • --bn-doc-page-width moved from an injected <head> style tag to an inline style attribute on bn-context. The head is never touched by the morph, so a format/orientation change would have kept the old width; attributes are synced, so it updates live now.
  • preview.css pins the document container to the paper width. The generic bn-context { min-width: 100% } rule was beating the doc rule's max-width, so the previewed "page" followed the browser window — embedded components sized and validated against a width the built PDF does not have.
  • The "No content was broadcast for …" toolbar pill is removed. With selective refreshes this fires for every view that simply was not affected by a change, which reads as a failure when nothing failed. Real render failures already reach the toolbar through path-scoped refresh-error events; the console warning stays for debugging.

refresh.Run gets its first test: it proves doc routes end up in the broadcast list and the context cache serves the rendered document (both failed before the fix). The width helper has a table-driven test for the format/orientation mapping.

internal/web/static/preview.js is regenerated from source.

The doc loop in refresh.Run only swapped the static route and never
called BroadcastContent, so /doc/* views stayed stale until a manual
reload, showed a false 'Refresh failed' pill on every refresh, and the
/__preview/context endpoint 404'd for doc paths forever. Broadcast the
styled doc HTML like the report loop does; swapContext already extracts
the bn-context from a full page, so no pipeline change is needed.

The --bn-doc-page-width custom property moves from a head style tag to
an inline style attribute on bn-context so it participates in the
attribute sync on SSE morphs (format/orientation edits update live).

preview.css pins the doc container to the paper width: the generic
bn-context min-width:100% beat the doc rule's max-width, so the
previewed page tracked the browser window instead of the PDF geometry
and embedded components validated against window-dependent widths.

The no-payload toolbar pill is removed: selective refreshes legitimately
skip unaffected views, and every real render failure already surfaces
via path-scoped refresh-error events. The console warning stays.
out = append(out, tag...)
out = append(out, doc[idx:]...)
insertAt := idx + len(openTag)
out := make([]byte, 0, len(doc)+len(attr))
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.

2 participants