Skip to content

Untangle circular imports for an acyclic module graph #398

Closed

Description

@ccombe

Problem

madge --circular modules/react-arborist/dist/module/index.js reports one cycle:

data/create-root.js > interfaces/node-api.js

node-api.ts imports ROOT_ID from create-root.ts, and create-root.ts imports NodeApi back from node-api.ts. Two more patterns add cycles whenever the module graph grows: value imports where only a type is needed, and state slices importing initial.ts / root-reducer.ts for their initial slices.

(An earlier version of this issue cited 21 loops. That count came from an intermediate state of the migration branch and does not reproduce on main or on #391; the measured number on both is 1.)

Proposed change

  • Move ROOT_ID into interfaces/node-api.ts and re-export it from data/create-root.ts.
  • Define slice-local initial state constants (initialDragState, initialSelectionState, initialDndState) so slices do not import initial.ts / root-reducer.ts.
  • Use import type for type-only imports. The default renderer imports in interfaces/tree-api.ts stay as value imports: the renderRow / renderNode / renderCursor / renderContainer / renderDragPreview getters keep their || DefaultX fallbacks, so removing those imports would change what the getters return.

Acceptance

  • madge --circular modules/react-arborist/dist/module/index.js reports 0.
  • No behavior change and no change to the public API; unit and e2e tests pass.

Branch with the work: untangle-circular-deps, opened as #400.

Activity

  1. ccombe commented on Oct 31, 2026

    @ccombe
    ContributorAuthor

    Delivered by #400. The PR body carries the problem statement and acceptance criteria, including why the renderer imports in tree-api.ts stay value imports. Reopen if the approach in #400 needs to change.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions