best-practices: Visualizations (factory pattern + per-instance settings) - #5
Merged
topkoa merged 2 commits intoJul 6, 2026
Merged
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
This was referenced Jul 6, 2026
topkoa
force-pushed
the
docs/best-practices-performance
branch
from
July 6, 2026 04:25
335dddc to
1f05a21
Compare
Add a "Visualizations" section to the best-practices guide for type: "visualization" plugins, ground-truthed against the Host's renderer contract and the recent splitscreen/settings fixes. - Factory pattern (rule 15): window.feedBackViz_<id> MUST be a factory function returning a fresh renderer per call — this is what makes splitscreen's N simultaneous panels work; a singleton shares one context/canvas/meshes across panels and collides. Includes the renderer interface (draw required; init/resize/destroy/contextType/readyPromise optional) and lifecycle. - Per-instance resources + destroy() cleanup (16); read-only per-frame bundle, allocation-free draw() (17); self-detect canvas size drift (18). - Settings communication (19): declare `settings` on the visualization capability and implement applySetting(key, value) on the instance — the Host applies each change to the specific per-panel instance (inherently per-panel). Documents the concrete failure modes recent fixes addressed: apply-live-never- reload, no cross-setting leakage (backfill once, don't mirror on read), deliberate per-panel vs global key scoping, fan-out to all panels, and the settings panel loading before the renderer. - Fail-safe auto-revert (20): guard draw() or the Host reverts to default after repeated throws. Renumber the Shipping section to 21-25 and add a Visualizations checklist block. Docs only. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: K. O. A. <topkoa@gmail.com>
… (rule 19) Rule 19 said "the Host owns persistence" but never addressed localStorage. Make it explicit: prefer Host-owned persistence (declare the setting, apply live, let the Host store/replay) and do not hand-roll settings into localStorage — that is what keeps export/import and backups whole and stops per-panel copies drifting. For a self-managed viz that predates the contract, add the quota-safe rule from the fixes: localStorage is synchronous and can throw (quota / private mode), so stage the value in an in-memory fallback before setItem and prefer it on read, and never touch localStorage on a per-frame path. Add a matching checklist item. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: K. O. A. <topkoa@gmail.com>
topkoa
force-pushed
the
docs/best-practices-visualizations
branch
from
July 6, 2026 04:25
e792ad2 to
b2040e8
Compare
Base automatically changed from
docs/best-practices-performance
to
docs/client-runtime-section
July 6, 2026 04:42
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.
Summary
Adds a Visualizations section to the best-practices guide for
type: "visualization"plugins — the factory pattern for splitscreen compatibility, and the per-instance settings-communication pattern (including the concrete failure modes the recent fixes addressed). Traced against the Host's actual renderer contract and the June–July settings/splitscreen commits, not written from memory.Why a factory (rule 15)
window.feedBackViz_<id>must be a factory function returning a fresh renderer per call. Splitscreen creates one highway per panel and calls the factory once per panel, so N panels get N independent renderers. A singleton would have every panel fight over one WebGL context / canvas / mesh set — the classic splitscreen bug. Includes the renderer interface (drawrequired;init/resize/destroy/contextType/readyPromiseoptional) and the Host lifecycle.Settings communication (rule 19) — the recent-fixes part
Forward pattern: declare a
settingsarray on thevisualizationcapability and implementapplySetting(key, value)on the renderer instance. The Host validates the descriptors, owns persistence, and callsapplySettingon each specific per-panel instance — inherently per-panel, no shared global keys, no canvas→panel lookup to get wrong.Documents the actual failure modes recent commits fixed:
location.reload()(it drops the user out of settings).Plus: per-instance resource ownership +
destroy()cleanup (16), read-only per-frame bundle / allocation-freedraw()(17), self-detect canvas size drift (18), and fail-safe auto-revert (20). Checklist gains a Visualizations block; Shipping section renumbered to 21–25.Scope & stacking
Docs only (
spec/best-practices.md+CHANGELOG.md). No version bump. Framed the concrete API names (feedBackViz_<id>,applySetting) as the current Host contract, principles as stable.Stacked on #3 (base
docs/best-practices-performance) since it extends the same file — the section sits right after "Client screen & the shared main thread." Full stack is now #2 → #4 → #3 → #5.mkdocs build --strictandcheck_versions.pypass; headings contiguous 1–25.🤖 Generated with Claude Code