Cables paint over devices and their invisible hit areas block ports - sockets under a cable cannot be clicked #2

Closed
opened 2026-11-08 06:05:40 +00:00 by jaylouisw · 1 comment
Owner

Ported from GitHub Jaylouisw/packetforge#66, filed before Forgejo became the source of truth.

Summary

Cables are rendered after the devices inside #world, so every cable paints on top of every device — and the invisible click target for each cable (line.link-hit) sits over the port sockets. Once a router has a couple of cables attached, the rest of its ports become unclickable: clicking a socket selects the cable that happens to cross it instead.

This makes it impossible to fully cable any device that already has a link.

Evidence

#world child order — all eleven device groups come first, then the link lines:

['g:d2','g:d3','g:d4','g:d5','g:d6','g:d7','g:d8','g:d9','g:d10','g:d11','line','line','line', ...]

Because SVG paints in document order, every line is drawn above every device group.

Ports that are now unclickable

elementFromPoint at each port dot's centre on the router (d3, RT-AX89X), which had four cables attached at the time:

wan       cx=481 cy=112  hit: circle.port connected        <- clickable
lan2      cx=481 cy=121  hit: circle.port connected        <- clickable
lan4      cx=481 cy=130  hit: circle.port                  <- clickable
lan6      cx=481 cy=139  hit: circle.port                  <- clickable
lan8      cx=481 cy=148  hit: circle.port                  <- clickable
10g-sfp   cx=481 cy=157  hit: circle.port connected        <- clickable
radio1    cx=481 cy=166  hit: circle.port                  <- clickable
lan1      cx=584 cy=113  hit: circle.port connected        <- clickable
lan3      cx=584 cy=124  hit: line.link ... selected       <- BLOCKED
lan5      cx=584 cy=134  hit: line.link-hit                <- BLOCKED
lan7      cx=584 cy=144  hit: line.link-hit                <- BLOCKED
10g-rj45  cx=584 cy=154  hit: line.link-hit                <- BLOCKED
radio0    cx=584 cy=164  hit: line.link-hit                <- BLOCKED

Five of twelve sockets on this router are dead to the mouse. Attempting to click lan3 does not arm a connection — status stays idle, nothing is sent, no error is shown. Same silent failure as #61, different cause.

There is nothing on screen to indicate why: the cables are thin lines that visually pass near the sockets, and the blocking element is an invisible fat stroke.

Why it happens

Two separate faults combine:

  1. Links are appended to #world after the devices (see the child order above), so they paint over the faceplates. Cables should sit below devices — a cable running across a device body should disappear behind it, which is also how the device currently gets visually clipped.
  2. line.link-hit is a wide transparent stroke used as a click target for selecting a cable, and it inherits the same stacking position — above the ports. A 2 px visible cable is backed by a hit area several pixels wide, easily wide enough to cover a 6–10 px socket.

Reproduction

  1. Place a router with many ports and two or three other devices.
  2. Cable three or four of its ports. Each cable is drawn from its socket.
  3. Try to cable any remaining port that has a cable passing near it. Nothing happens; the click selects a cable instead (see the status bar change to Link: ...).

Suggested fix

Give links their own layer, inserted before the device groups:

// canvas.js — render(): create/keep one links group, always first
linksLayer = linksLayer || el('g', { id: 'links' }, world, true /* prepend */);

then append cables into linksLayer instead of world. That fixes both the visual clipping and the hit-testing in one move.

Additionally:

  • .link { pointer-events: none; } — the visible stroke should never be clickable.
  • Keep line.link-hit as the click target, but put it in the same linksLayer (so it is below the devices and therefore below the ports), and narrow it to roughly stroke-width: 6 rather than something that can span a whole faceplate.
  • If a cable genuinely must be selectable while it overlaps a device, prefer making the device win the hit test — ports and body are the primary interaction, cable selection is secondary.

Impact

  • A device can be cabled only until the first cable crosses the remaining sockets; after that, part of its port field is permanently unreachable without deleting and re-adding cables.
  • Silent: no toast, no console error, no visual cue. The user just finds that some ports "don't work".
  • Compounds #61 (ghost cable covering the destination socket). Between the two, most cabling attempts on a busy device fail with no explanation.

Notes

  • Found while cabling a ten-device network: the first four links went in fine; after that, the router's entire right-hand port column stopped responding, and the remaining hosts could only be attached via the left-hand ports that no cable happened to cross.
  • The same ordering means cables are also drawn across device faceplates and port labels rather than behind them.
> Ported from GitHub `Jaylouisw/packetforge#66`, filed before Forgejo became the source of truth. ## Summary Cables are rendered **after** the devices inside `#world`, so every cable paints on top of every device — and the invisible click target for each cable (`line.link-hit`) sits over the port sockets. Once a router has a couple of cables attached, the rest of its ports become **unclickable**: clicking a socket selects the cable that happens to cross it instead. This makes it impossible to fully cable any device that already has a link. ## Evidence `#world` child order — all eleven device groups come first, then the link lines: ``` ['g:d2','g:d3','g:d4','g:d5','g:d6','g:d7','g:d8','g:d9','g:d10','g:d11','line','line','line', ...] ``` Because SVG paints in document order, every `line` is drawn above every device group. ### Ports that are now unclickable `elementFromPoint` at each port dot's centre on the router (`d3`, RT-AX89X), which had four cables attached at the time: ``` wan cx=481 cy=112 hit: circle.port connected <- clickable lan2 cx=481 cy=121 hit: circle.port connected <- clickable lan4 cx=481 cy=130 hit: circle.port <- clickable lan6 cx=481 cy=139 hit: circle.port <- clickable lan8 cx=481 cy=148 hit: circle.port <- clickable 10g-sfp cx=481 cy=157 hit: circle.port connected <- clickable radio1 cx=481 cy=166 hit: circle.port <- clickable lan1 cx=584 cy=113 hit: circle.port connected <- clickable lan3 cx=584 cy=124 hit: line.link ... selected <- BLOCKED lan5 cx=584 cy=134 hit: line.link-hit <- BLOCKED lan7 cx=584 cy=144 hit: line.link-hit <- BLOCKED 10g-rj45 cx=584 cy=154 hit: line.link-hit <- BLOCKED radio0 cx=584 cy=164 hit: line.link-hit <- BLOCKED ``` Five of twelve sockets on this router are dead to the mouse. Attempting to click `lan3` does not arm a connection — status stays idle, nothing is sent, no error is shown. Same silent failure as #61, different cause. There is nothing on screen to indicate why: the cables are thin lines that visually pass *near* the sockets, and the blocking element is an invisible fat stroke. ## Why it happens Two separate faults combine: 1. **Links are appended to `#world` after the devices** (see the child order above), so they paint over the faceplates. Cables should sit *below* devices — a cable running across a device body should disappear behind it, which is also how the device currently gets visually clipped. 2. **`line.link-hit` is a wide transparent stroke used as a click target** for selecting a cable, and it inherits the same stacking position — above the ports. A 2 px visible cable is backed by a hit area several pixels wide, easily wide enough to cover a 6–10 px socket. ## Reproduction 1. Place a router with many ports and two or three other devices. 2. Cable three or four of its ports. Each cable is drawn from its socket. 3. Try to cable any remaining port that has a cable passing near it. Nothing happens; the click selects a cable instead (see the status bar change to `Link: ...`). ## Suggested fix Give links their own layer, inserted **before** the device groups: ```js // canvas.js — render(): create/keep one links group, always first linksLayer = linksLayer || el('g', { id: 'links' }, world, true /* prepend */); ``` then append cables into `linksLayer` instead of `world`. That fixes both the visual clipping and the hit-testing in one move. Additionally: - `.link { pointer-events: none; }` — the visible stroke should never be clickable. - Keep `line.link-hit` as the click target, but put it in the same `linksLayer` (so it is below the devices and therefore below the ports), and narrow it to roughly `stroke-width: 6` rather than something that can span a whole faceplate. - If a cable genuinely must be selectable while it overlaps a device, prefer making the *device* win the hit test — ports and body are the primary interaction, cable selection is secondary. ## Impact - A device can be cabled only until the first cable crosses the remaining sockets; after that, part of its port field is permanently unreachable without deleting and re-adding cables. - Silent: no toast, no console error, no visual cue. The user just finds that some ports "don't work". - Compounds #61 (ghost cable covering the destination socket). Between the two, most cabling attempts on a busy device fail with no explanation. ## Notes - Found while cabling a ten-device network: the first four links went in fine; after that, the router's entire right-hand port column stopped responding, and the remaining hosts could only be attached via the left-hand ports that no cable happened to cross. - The same ordering means cables are also drawn across device faceplates and port labels rather than behind them.
Author
Owner

Fixed, and it took two changes because the report contains two defects:

  1. Paint order — web/canvas.js now builds two explicit layers, cable-layer then device-layer, so cables paint behind devices instead of over the faceplate.
  2. Hit order — hit testing was e.target.closest(...), so whatever the browser painted last at that pixel decided what the mouse hit. It is now explicit geometry with a precedence: port, then device body, then cable, then background. Reordering the DOM alone would have moved which element was in the way, not removed it.

test/canvas-hit-testing.test.js (27 checks) drives real pointerdown events at the coordinates of a socket with a cable drawn over it and asserts which handler ran, plus the paint order of the resulting drawing.

Fixed, and it took two changes because the report contains two defects: 1. **Paint order** — `web/canvas.js` now builds two explicit layers, `cable-layer` then `device-layer`, so cables paint *behind* devices instead of over the faceplate. 2. **Hit order** — hit testing was `e.target.closest(...)`, so whatever the browser painted last at that pixel decided what the mouse hit. It is now explicit geometry with a precedence: port, then device body, then cable, then background. Reordering the DOM alone would have moved which element was in the way, not removed it. `test/canvas-hit-testing.test.js` (27 checks) drives real pointerdown events at the coordinates of a socket with a cable drawn over it and asserts which handler ran, plus the paint order of the resulting drawing.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge#2
No description provided.