-
-
Notifications
You must be signed in to change notification settings - Fork 2
Contributing a File Viewer
itsmylab edited this page Aug 4, 2026
·
1 revision
Generated from
docs/contributions/file-viewer.md. Edit the canonical source through a pull request.
Use this playbook to render another file type natively and offline when a file opens in Canopy.
flowchart LR
Path[File path]
Kind[viewerKindFor]
Read[Rust bounded byte read]
Dispatch[File view dispatch]
Parser[Lazy parser or blob URL]
Render[Offline viewer]
Source[Optional source/diff toggle]
Path --> Kind --> Read --> Dispatch --> Parser --> Render
Render --> Source
Viewers receive bytes from the scoped Rust filesystem boundary. They do not read arbitrary paths or fetch a hosted renderer.
src/components/viewers.tsx ViewerKind, extension mapping, viewer component
src/fileOpen.ts size/binary refusal policy
src/components/FileView.tsx render dispatch and source toggle
src/types.ts open-file metadata when needed
Use nearby viewer tests or add viewers.test.tsx for the new behavior.
- Add a stable
ViewerKindmember. - Map only the supported extensions in
viewerKindFor. - Decide whether a text source view is meaningful.
- Define maximum safe input and binary behavior before parsing.
- Implement a component that accepts the already-read bytes and path metadata.
- Lazy-load a heavy parser so unrelated file opens do not pay its cost.
- Sanitize generated HTML before rendering it.
- For blob URLs, copy bytes when needed and revoke URLs on cleanup.
- Cancel or ignore async parser completion after unmount.
- Add render dispatch and source/diff toggle behavior.
- Handle empty, corrupt, oversized, unsupported, and parser-error states.
- Test extension mapping, successful render, refusal, cleanup, and fallback.
sequenceDiagram
participant View
participant Parser as Lazy parser
participant Resource as Blob/model/resource
View->>Parser: import and parse bounded bytes
Parser-->>View: result or error
View->>Resource: create render resource
View-->>View: render
View->>Resource: revoke/dispose on change or unmount
npm run test -- src/fileOpen.test.ts
npm run typecheck
npm run buildAdd and run a focused viewer component test for the new renderer; there is no
generic viewers.test.tsx file today.
- Viewer kind and extensions are narrow and explicit.
- Read/size policy is defined before parsing.
- Heavy dependency is lazy-loaded.
- Generated HTML is sanitized.
- Blob/model/parser resources are disposed.
- Source and fallback behavior are defined.
- Empty, corrupt, oversized, and unsupported cases tested.
- Viewer works offline.
Generated from FluidWorksApp/canopy-ide. Canonical documentation changes belong in the main repository.
Canopy Architecture
- Home
- Architecture
- Core Rust System
- LLM Context
- Integration Guide
- Contribution Playbooks
- Testing and Coverage
- Publish the Wiki
Playbooks