Behaviour SwRS-MDOKFSTUDIO-LIFE-039
Typing renders the new text after a short pause, without writing files
When the text of a document changes, saved or not, the extension SHALL queue a render of the new text in every preview that shows that document, start it after a pause of 40 ms or of twice the last render time when that is longer (at most 1 s), or at once after a block edit is committed, let a running render finish first unless it has run more than 1 s and more than twice the wall-clock time of the last render when the newer render is due (then abort it), without writing to the shown file or to any build output folder of the workspace; a preview whose panel is hidden SHALL not render until the panel is shown, and previews of the same document, revision and render options SHALL share one render.
Step 1 of path 1 in StRS-MDOKFSTUDIO-LIFE-005: from “A preview shows a document” to “A new render is done”.
Scenarios 8
The situations the tests check; open one to read it.
nominalUnsaved edit
refusalSource gone
boundaryCollecting edits for 40 ms
| Input | Outcome |
|---|---|
| five changes within 40 ms | when the 40 ms elapse one render starts and the page receives the last text once |
| a pending edit that the preview cancels before the delay ends | when the delay elapses the builder is never invoked |
| the last render took 300 ms | the next render starts 600 ms after the last change, not 40 ms |
| the last render took under 10 ms | the next render starts 40 ms after the last change |
| the last render took 3 s | the next render starts 1 s after the last change (the upper bound) |
| the last render took 300 ms and the writer commits a block edit (the editor closes on an applied edit) | the render starts at once, without the 600 ms pause; a running render still finishes first |
boundaryEdits during a render
| Input | Outcome |
|---|---|
| a render of 500 ms running and two newer edits queued | when the running render ends its result is shown and the render of the newest edit starts at once; the older queued edit is superseded |
| a render whose buffer already changed | when the render ends its result is still shown, so the preview keeps moving while the writer types, and the newer render follows |
| the first render (no render time known yet) and a newer edit | the first render always finishes |
| the last render took 600 ms of wall-clock time, the running one has run 1.25 s when the newer edit's pause elapses | the running render is aborted (its worker thread stops, see SwRS-MDOKFSTUDIO-LIFE-004), the newest edit renders at once, a late result of the aborted render is dropped, and the time the aborted render ran becomes the estimate of the pause and of the overrun limit until a render completes |
| a small document: the MyST render takes 2 ms, the whole render 60 ms of wall-clock time, and a newer edit's 40 ms pause elapses during it | the running render finishes and the newer edit renders right after; no render is aborted before it has run 1 s |
boundaryHidden panels and shared renders
| Input | Outcome |
|---|---|
| a preview whose panel is hidden and a change, a refresh or a document switch | no render starts; the preview is marked dirty |
| the dirty panel is shown | one render starts, and the mark is cleared |
| two previews of the same document at the same revision, workspace root, trust state, restricted-reads state and PlantUML engine | one render serves both; each receives its own stage with its own request id |
| a file the render may have read changes, a setting changes, files are renamed or a refresh is requested | the next request renders again instead of joining a finished render |
nominalRendering writes nothing
refusalSave of a buffer the preview already shows
| Input | Outcome |
|---|---|
| a ready render of revision 7 and a save of the buffer at revision 7, the file watcher reports the saved file | no render starts (the activePathChanges probe counts the event, the requestId is unchanged) |
| the buffer is at revision 8 while the page shows revision 7, or the page shows an error, the watcher reports the file | a render starts |
boundaryThe previewReady message
| Input | Outcome |
|---|---|
| a previewReady with the envelope (documentId, revision, requestId) and the optional state fields of a page-state message (line, endLine, sourceLine and selectionLine of at least 1, anchorLine of at least 1, scrollTop of at least 0, previewThemeMode, anchorToEditor, editMode, request) and blockEditOpen as a boolean | accepted as a message (see SwRS-MDOKFSTUDIO-TRUST-052); the host records the reported reading state and the render the page listens for |
| a previewReady that reports blockEditOpen false, or names another render than the one the host holds | the host releases an edit lock that waited for a page editor, so the lock cannot block every later edit |
| blockEditOpen on any type other than previewReady, or an invalid optional field | not a message, ignored (see SwRS-MDOKFSTUDIO-TRUST-052) |
| a previewReady that names an older render than the host holds | handled by the gate of its type (see SwRS-MDOKFSTUDIO-TRUST-065) |
Implemented in 8
Tested by 9
- test/core/state/editLock.test.tsunit
- test/host-memory/memoryHostSession.test.tsunit
- test/host/lifeReq.requirements.test.tsunit
- test/host/previewTiming.test.tsunit
- test/integration/dirtySnapshots.test.tsintegration
- test/node-services/build/buildQueue.test.tsunit
- test/session/eventFanOut.test.tsunit
- test/session/previewManager.test.tsunit
- test/session/sharedRenders.test.tsunit