Skip to content

fix: write every sheet file for hierarchical KiCad schematic exports - #4960

Open
wroscoe wants to merge 1 commit into
tscircuit:mainfrom
wroscoe:fix/kicad-hierarchical-sheet-export
Open

wroscoe wants to merge 1 commit into
tscircuit:mainfrom
wroscoe:fix/kicad-hierarchical-sheet-export

Conversation

@wroscoe

@wroscoe wroscoe commented Sep 26, 2026

Copy link
Copy Markdown

Problem

When a design uses schSheetName (hierarchical schematic), tsci export -f kicad_zip and tsci build --kicad-project / --kicad-project-zip produce a KiCad project whose schematic is empty:

  • CircuitJsonToKicadSchConverter.getOutputString() returns only the root sheet for hierarchical schematics (this.files[0].content).
  • The root sheet contains (sheet ...) blocks whose Sheetfile properties point at sheet_1.kicad_sch, sheet_2.kicad_sch, ...
  • Those child files are never written, so KiCad opens an empty root sheet with broken sheet links, and every symbol is missing.

The export still exits 0 and the zip contains exactly one .kicad_sch, so nothing flags it. PCB output is unaffected.

We hit this on a 3-sheet board: the exported index.circuit.kicad_sch was 2.7 KB with 0 symbols and three Sheetfile references to files not in the zip.

Fix

circuit-json-to-kicad already provides getOutputFiles({ schematicFilename }), which returns the root plus every child sheet (and just the root for non-hierarchical designs). Use it in both places:

  • lib/shared/export-snippet.ts: the kicad_zip export
  • cli/build/generate-kicad-project.ts: build --kicad-project / --kicad-project-zip, which zips the output dir

GeneratedKicadProject.schContent still holds the root sheet, so its shape is unchanged. Output for non-hierarchical schematics is byte-for-byte the same.

Tests

  • tests/cli/export/export-kicad.test.ts: a two-sheet circuit exported with kicad_zip. Asserts the zip contains the root plus sheet_1/sheet_2, that the root references both files, and that each child holds its symbol.
  • tests/cli/build/build-kicad-project-zip.test.ts: the same circuit through build --kicad-project, asserting all three .kicad_sch files are written.

tsc --noEmit and biome format pass locally. I couldn't run the test suite locally because my sandbox blocks some outbound hosts the render path uses, so this PR is a draft until CI is green.

🤖 Generated with Claude Code

`tsci export -f kicad_zip` and `tsci build --kicad-project[-zip]` wrote
only `schConverter.getOutputString()`, which for a hierarchical schematic
(components using `schSheetName`) is just the root sheet. The root sheet
references `sheet_*.kicad_sch` files that were never written, so the
exported project opens with an empty schematic and broken sheet links.

Use `getOutputFiles()` so the root and every child sheet are written. For
non-hierarchical schematics it returns the single root file, so output is
unchanged there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@wroscoe
wroscoe marked this pull request as ready for review September 26, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant