Repository navigation
ui: let a host refuse a diagram fence by its source, before any engine runs - #4146
Merged
Merged
Conversation
…e runs - New opt-in DiagramSourceAcceptContext (components/diagramSourceAccept, type DiagramSourceAccept, also in the components/diagram barrel): (kind, source) => boolean, asked by useDiagramRender before renderDiagram. kind is 'mermaid' or 'graphviz'; source is the fence's text as written. Asked synchronously, once per (check, kind, source). Only true accepts; a check that throws refuses that fence and never falls back to an engine. - A refused fence loads no engine (Pele, Mermaid, Graphviz), is not parsed or drawn, and resolves to the same refused result an accept refusal gives, so the block shows its source as code. accept still runs after it. - Code review: ReviewDiagramFence asks the same check and does not import its diagram engine for a refused fence; the engine shares the context module with the page (DIAGRAM_ENGINE_SHARED_MODULES). - Absent: every render is exactly as before. Plannotator's apps pass none. - Tests: components/diagram/diagramSourceAccept.test.tsx (DOM), a ReviewDiagramFence case in MarkdownFilePreview.test.tsx, and browser tests in diagram-remote-loads.spec.ts: refused, with no CSP, no request to another host and no engine loaded; accepted, as with no check. - Docs: README and HANDOFF (layers, what a host must do itself, what changed for hosts), code-review guide.
… result A fence that was drawn and is then refused by the host's source check (its source changed in place, or a new check function) now shows exactly what a fresh refusal shows: no drawing, no controls, and an open pop-out closes. A parse error still keeps the last good render. The check's answer is remembered per function, kind and source so the block and its viewers share one call. DIAGRAM_REFUSED_RESULT is frozen. A structural test keeps renderDiagram and the engine loaders to their allowed callers inside packages/ui. The docs say which paths the check covers and how to supply a check whose policy loads later or changes.
Remove the page-wide remembered answers: an answer now lives in the mounted component that asked, and a remount asks again. A diagram block hands its answer to its inline view and pop-out through a context scoped to the block, so the host is still asked once per mounted block. The structural test also covers the loaded-engine getters and the engine packages' dynamic imports, and scans whole files.
backnotprop
marked this pull request as ready for review
November 27, 2026 18:33
yermakoffivan
pushed a commit
to yermakoffivan/plannotator
that referenced
this pull request
Nov 27, 2026
…d Pele 1.13 core 0.25.35 carries what merged after 0.25.34 went to npm: exact-phrase search in inbox-search (words in double quotes, backnotprop#4117, backnotprop#4124) and the agent-gone event in external-annotation's ExternalAnnotationEvent (backnotprop#3698). No exports subpath changes. ui handles that agent-gone event, so its pin follows and core goes first. ui 0.67.0 is a minor: DiagramSourceAcceptContext lets a host refuse a fence by its source before any engine runs (backnotprop#4146), DIAGRAM_REFUSED_RESULT is exported, Pele 1.13.0 with the inline fit changes (backnotprop#4113), the agent-gone send failures (backnotprop#3698) and the plan header seams (backnotprop#3905). README and HANDOFF name the new pair and the order (core first), and the hook and Pele notes now name ui 0.67.0 instead of "the first ui after 0.66.0". bun.lock is bun install's own output: the two package version lines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lets a host that consumes
@plannotator/uirefuse a diagram fence by its source, before either engine runs. Until now the only host hook,accept(DiagramSvgAcceptContext), was handed the finished svg, after the engine had already run.What it is
DiagramSourceAcceptContext(components/diagramSourceAccept, typeDiagramSourceAccept, also exported from thecomponents/diagrambarrel): an optional React context holding(kind, source) => boolean. It follows the same convention asDiagramSvgAcceptContext: its own small module, so a host can provide it per subtree without importing the diagram engine.useDiagramRenderasks it beforerenderDiagram, synchronously, once per (check, kind, source). A theme change or a Retry does not ask again.kindis'mermaid'or'graphviz'.sourceis the fence's text as written, before any rewriting (the sankey header normalisation runs later, inside the Pele path).trueaccepts. A check that throws refuses that fence (with aconsole.warn), and the rest of the page renders. Unlikeacceptunder Pele, a throw never sends the fence on to Mermaid.refusedresult anacceptrefusal gives (DIAGRAM_REFUSED_RESULT, now exported fromutils/diagram-render), so the block shows its source as code, with no Expand. There is no new UI and there are no new words.acceptstill runs after it, as before.ReviewDiagramFenceasks the same check and does not import its diagram engine for a refused fence. The engine shares the context module with the page (DIAGRAM_ENGINE_SHARED_MODULES), and the engine build passes.It stops the engines from running for a refused fence. It does not replace
diagramRemoteLoads: falseor an enforced page CSP, which still decide what an accepted fence loads.Tests
packages/ui/components/diagram/diagramSourceAccept.test.tsx(DOM, registered intests/dom-test-list.txt). The engines are counted through their loader seams. A refused fence givesrefused, with zero Pele, Mermaid and Graphviz loads, no parse and nothing added outside the block. It looks the same as anacceptrefusal. A theme change does not ask again. Accepted renders the same as no check. A check that throws refuses. Onlytrueaccepts. With one fence accepted and one refused, the engines load only for the accepted one. The sankey header row reaches the check as written.MarkdownFilePreview.test.tsx: a refusedReviewDiagramFencenever imports the engine, and an accepted one beside it does.tests/e2e/diagram-remote-loads.spec.ts(Chromium and WebKit, throughuseDiagramRenderin a React mount): with a refusing check and no CSP, every source in the file makes zero requests to another host and loads no engine. This holds when Mermaid draws every fence and with the switch as shipped. With an accepting check, the sources behave as with no check.Release
No version bump. The new module is covered by the existing
./components/*export wildcard. The docs say it ships in the first ui after 0.66.0.