fuse without voltageRating renders a bare unit: "1A / V" on the schematic, "V" in circuit JSON

Open Beginner friendly
#2,833 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
react, typescript
Domain
frontend, testing

Research direction

Start in lib/components/normal-components/Fuse.ts and compare its display formatting with Resonator. Run tests/components/normal-components/fuse.test.tsx, then inspect the mentioned schematic snapshot tests for the missing-voltage case. Done means a fuse with only currentRating no longer emits a bare V in schematic or circuit JSON, with regression coverage for the optional field.

Written by the indexing model from the issue text.

Description

What happens

A <fuse /> without voltageRating renders a bare unit with no number — on the schematic symbol and in circuit JSON:

<fuse name="F1" currentRating="1A" footprint="0402" />
source_component.display_current_rating  "1A"
source_component.display_voltage_rating  "V"      ← no value
schematic_component.symbol_display_value "1A / V" ← rendered on the schematic

voltageRating is optional in the props schema (voltageRating?: number | string), while currentRating is required — a fuse without a currentRating fails validation outright (Invalid props for fuse "F4": currentRating (Required)). So "current only" is a fully supported, and probably common, way to declare a fuse, and it's the case that renders wrong.

Cause

lib/components/normal-components/Fuse.ts interpolates the formatted value unconditionally:

display_voltage_rating: `${formatSiUnit(voltageRating)}V`,
...
return `${formatSiUnit(current)}A / ${formatSiUnit(voltage)}V`

formatSiUnit(undefined) returns "", so the template collapses to just the unit suffix.

Prior art in this repo

Resonator._getSchematicSymbolDisplayValue() already handles exactly this shape correctly — it drops the optional half rather than emitting an empty unit:

const freqDisplay = `${formatSiUnit(this._parsedProps.frequency)}Hz`
if (this._parsedProps.loadCapacitance) {
  return `${freqDisplay} / ${formatSiUnit(this._parsedProps.loadCapacitance)}F`
}
return freqDisplay
Why no test catches it

tests/components/normal-components/fuse.test.tsx is the only fuse component test and it passes both ratings, so the optional-field path is never exercised.

Interestingly the repo already contains schematic snapshots showing the bug, they just weren't recognised as wrong:

  • tests/features/schematic-text-bounding-box/schematic-text-bounding-box-fuse.test.tsx — four fuses, all currentRating="2A" with no voltage, all rendering 2A / V.
  • schematic-section-rp2040.test.tsx and schematic-section-rp2040-autolayout.test.tsx<fuse name="F1" currentRating="500mA" />, rendering 500mA / V.

Happy to submit a PR (already have one ready).

Dominant language
TypeScript
Stars
58
Forks
203
Avg merge
7h 39m
Merged PRs (30d)
286

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tscircuit/core

All issues in tscircuit/core

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.