Behaviour SwRS-MDOKFSTUDIO-DIAG-009
Diagrams are drawn once per source and theme and late results are dropped
When the page needs a Mermaid diagram, a PlantUML diagram drawn by the built-in engine or a chart, the extension SHALL draw only the diagrams whose source or theme colours changed or that were never drawn, show an earlier drawing of the same source and theme colours without running the engine again, run the Mermaid and PlantUML draw passes one at a time (so a later Mermaid theme is drawn only after the running pass ends), and, for a PlantUML diagram or a chart, drop a result that arrives for a key the node no longer has. When the JAR pipeline renders a diagram text that an earlier successful render already drew, the extension SHALL reuse that SVG without starting a process.
Another outcome at step 3 of path 1 in StRS-MDOKFSTUDIO-DIAG-001, in the state “The diagram is drawn as a picture”.
Scenarios 7
The situations the tests check; open one to read it.
nominalUnchanged diagram after a node replacement
boundaryChanged source or theme
nominalA content patch draws only new diagrams
| Patch | Outcome |
|---|---|
| Adds a Mermaid diagram while another is already drawn | The page applies the patch and signals the replaced content; the new diagram is drawn and the earlier one is not rebuilt |
| The keyed morph keeps a drawn diagram through the patch | The diagram keeps its render state and its picture |
| Adds a PlantUML diagram next to a drawn one (built-in engine) | Only the new diagram, which has no render state, is drawn; the others are left untouched |
| Replaces a PlantUML node with the same source and variant | The kept result is shown and the engine is not run |
The page draws the diagrams that have no render state and leaves the diagrams that have one untouched.
boundaryDraw passes run one at a time
| Situation | Outcome |
|---|---|
| A content patch and a theme change are requested while a pass is running | The next pass starts only when the running pass finishes, in the order requested |
| A pass is requested before the Mermaid module has loaded | The pass starts after the load and not before |
refusalA late picture for a replaced key is not shown
| Situation | Outcome |
|---|---|
| A Mermaid diagram is being drawn for the dark theme and the theme changes to cream | The cream pass starts only after the dark pass ends (passes run one at a time, so no Mermaid result arrives for a replaced key); the dark drawing is stored in the cache and shown, then the cream drawing replaces it |
| A Mermaid drawing finishes while its key is still the node's key | It is shown |
| A PlantUML diagram is drawn, a theme switch starts a second render of the element, and the first finishes after the second | Only the second render's picture is shown; the first result is dropped and the element is unchanged |
| A chart is drawn, a newer theme replaces it while it runs | The result is cached and not shown |
refusalA late error for a replaced key is not shown
| Situation | Outcome |
|---|---|
| A PlantUML drawing fails after a newer render took the element | No error message is shown for the replaced key |
| A Mermaid drawing fails for the node's current key | The error message is shown and the state is error |
nominalThe JAR pipeline reuses an earlier render
| Input | Outcome |
|---|---|
| the same diagram text rendered twice under one JAR, with the same command, arguments, workspace root, security profile and JAR size and modification time | one process starts; the second render returns the same SVG |
| another diagram text, a replaced JAR, or an earlier failure | a process starts (a failed render is never kept) |
| a diagram text with an include, import, theme, pragma or environment-reading directive | it is never reused: a process starts each time |
Implemented in 3
Tested by 5
Known limits (4)
- The plan actions keep, reuse and render are wired in mermaidPreview.ts, which has no unit test.
- The listener in mermaidPreview.ts that draws after a content patch is covered only by the real VS Code scenario.
- Diagrams inside one pass are started together and document order only fixes their element ids.
- The JAR cache holds up to 64 diagrams in memory and is not cleared when a file read by an include directive changes, so such diagrams are simply never cached.