Skip to content

Separate the painter from Node so renderGraph bundles for a browser (behold, pinhole) #1069

Closed

Description

@lex00

The single-file viewer has to lay out and paint in the page, because a host that only passes a graph document cannot ask a server for SVG. behold's painter already bundles small, but it still pulls in Node built-ins through a few imports. This issue removes them in behold and in pinhole. Part of #1049, phase 2.

Today

  • renderGraph (src/render.ts:434) lays out with pinhole's layoutIr and paints with its renderSvg, plus behold's edge routing.
  • A scoping bundle of renderGraph with pinhole for the browser came to 126 KB minified, 45 KB gzipped, but still imported node:fs, node:path, node:url, node:child_process and node:module.
  • On origin/main those come from: src/icon-packs.ts:25-27, which reads icon files from disk with readFileSync (line 145); src/choudoufu-member.ts:36-37 (spawn, node:fs), imported by src/render.ts:31 for a constant and card fields; and pinhole 0.5.0, whose root src/index.ts:3 re-exports graphIr from src/chant.ts, which imports node:child_process, node:module, node:fs and node:path.
  • Scoping also found @kubernetes/client-node in the bundle's resolution through src/k8s-target.ts. On origin/main that file imports KubeconfigView as a type only (line 48), so this chain may already be gone. A fresh bundle will tell.

Change

  • Icons as a generated module, written by a script and checked in CI the way generate:graph-layout and check:graph-layout are, in place of disk reads at load.
  • Move what src/render.ts takes from src/choudoufu-member.ts into a module with no Node imports.
  • In pinhole, move the chant CLI wrapper to its own subpath export (for example @intentius/pinhole/chant) so the root entry imports no node:*. Release pinhole and bump it in behold.
  • A CI step that bundles src/render.ts with esbuild for --platform=browser, fails on any node: import, and prints the minified and gzipped sizes.

Done when

  • The CI bundle step exits 0 and its log shows the sizes.
  • pinhole's root entry bundles for the browser on its own (pinhole CI).
  • /api/graph SVG for example-terraform-estate is byte-identical before and after (snapshot test).
  • Icons still draw in an export of a fixture with AWS, GCP and Kubernetes cards.

Depends on

Nothing. Scoping listed it after #1057, but the files it changes sit outside the pipeline #1057 moves out of src/server.ts. If #1057 is in flight, rebase on it.

Not in this issue

Layout in a Web Worker and the viewer bundle (the single-file viewer build).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    epic:surfaceswave:2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions