Skip to content

Extract createScene and createLabelLayer #112

Closed

Description

@JadRizk

Part of #107.

Merge: held until 2.0 ships. Depends on #111.

Scope: move renderer setup, materials, geometry and render targets into a createScene(...) factory that returns its parts and a dispose. Move the label pool and tooltip into createLabelLayer(...). Disposal still goes through the existing reverse-order stack.

Acceptance: the same as #111, plus teardown order is unchanged in the recording.

Activity

  1. added
    refactorCode-quality refactor tracked under the code-quality direction issue
    on Oct 10, 2026
  2. JadRizk commented on Oct 10, 2026

    @JadRizk
    OwnerAuthor

    Scope notes

    Checked against origin/refactor/111-prepare-pack at d8d73b9. The PR body starts with "⏸ Held until 2.0 ships (see #107)", followed by "Stacked on #121".

    Files. All under packages/graph/src/, none exported:

    • scene.ts: createRenderer, createScene, resize
    • scene-meshes.ts: the edge, pad, node, fade and post builders
    • label-layer.ts: createLabelLayer
    • scene.test.ts, label-layer.test.ts
    • GraphCanvas.tsx
    • .changeset/graph-scene-labels.md: patch, "Internal restructure; no API or behaviour change."

    Why two factories. createRenderer builds the renderer, scene and camera where they're built today. packBuffers runs after it, then createScene. With seed={null}, three's uuid draws share Math.random with visualRandom. The harness can't see that order, because three draws from its own stream, so the split keeps #111's rule in place by construction.

    Disposal. Each resource registers through a track callback as it is built, rather than through one returned dispose. That keeps the 6 stack entries in order: renderer, targets, materials, geometries, labels, tooltip. The array order inside each entry stays the same, and each entry keeps its own try/catch, so a throw in one can't skip the others or leak the canvas.

    Other constraints

    • Labels are appended before the tooltip.
    • resize keeps its current call order.
    • viewWidth, viewHeight, viewport and pixelSize stay in GraphCanvas.
    • The ResizeObserver stays in GraphCanvas.
    • syncNodes gets GraphCanvas's mutable arrays by reference, and its call during construction stays.

    Unit-tested rather than recorded. Recording these would push the recordings past the 200 KB cap:

    • the renderer options (antialias, alpha: false, powerPreference)
    • autoClear = false
    • frustumCulled = false and an infinite bounding sphere on every mesh
    • the number and order of track entries
    • the DOM order inside the label layer

    Acceptance

    1. vitest run passes without -u, and git diff --exit-code packages/graph/src/__recordings__ is clean. That includes the dispose order in lifecycle.unmount and boot.resize.
    2. browser/graph.spec.ts passes, with its baselines unchanged.
    3. dist/index.d.ts and dist/index.d.cts are byte-identical to the Extract prepareGraph and packBuffers #111 branch, and the npm pack --dry-run file list is unchanged.
    4. A prettier-formatted diff of dist/index.js shows relocation only.
    5. Every new function is ≤ 60 code lines with cognitive complexity ≤ 12, and the graph lint warning count doesn't rise. If a declarative material builder goes over 60 lines, the PR says why.
    6. Built on refactor/111-prepare-pack. 🏷️ types(graph): drop the non-null assertions the compiler doesn't need #118 also has hunks in this region, so whichever merges later rebases.
  3. added a commit that references this issue on Oct 11, 2026
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

    refactorCode-quality refactor tracked under the code-quality direction issue

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions