Skip to content

Give a Responsive that shows Empty no slot, in both renderers - #37

Merged
archlemon merged 1 commit into
mainfrom
fix/responsive-empty-slot
Nov 28, 2026
Merged

archlemon merged 1 commit into
mainfrom
fix/responsive-empty-slot

Conversation

@archlemon

Copy link
Copy Markdown
Member

Summary

Follow-up to #36. A Responsive whose visible variant is Empty() still took a slot:

  • TUI: a blank line plus a gap on each side;
  • browser: a zero-height wrapper, but still a flex item, so it got a gap on each side.

For example, Column, Gap 1: a, Responsive(At(0, Empty()), At(30, …)), b on a narrow screen gave 3 lines between a and b in the terminal and 2 gaps in the browser. It now gives one gap in both.

TUI. After rendering its children, a Box drops those whose Responsive picked an empty variant at the width they were given, looking through Keyed and nested Responsives. They're rendered first, so their picks stay recorded for the focus ring (#34). The check runs again after a wrapping Row collapses.

Browser. The wrapper must stay a box because it's the query container, and container queries can only style descendants, never the wrapper itself. So for a Responsive with an Empty variant directly inside a gapped Column:

  • describe (which now knows the parent's gap) marks the wrapper and its empty variants, and adds a per-instance rule that cancels one gap with a negative end margin while the wrapper is flagged empty;
  • the patcher keeps one ResizeObserver on such wrappers and sets the flag while an empty variant is the one displayed. ResizeObserver runs after layout and before paint, so there's no visible jump, and it tracks live window resizes.

Not fixed: Rows. Inside a browser Row the wrapper reserves its widest breakpoint's width whatever it shows (the existing limitation from #5), and a gap correction can't remove that. I tried two ways to collapse it:

  • zero width removes what the container queries measure, so it would stay stuck on the narrow variant;
  • a negative margin of its own width lets it grow back to its basis, which flips the variant and loops.

The limitation is now in the README. The TUI drops the slot in Rows too.

Test plan

  • rempty_test.go: Column with and without a gap, Row, Keyed and nested Responsive, both widths. Five of six cases fail on main. Also checks that focus picks stay aligned when a Responsive is dropped.
  • vdom_test.go: the gap-cancel markup appears only for a gapped Column with an Empty variant
  • e2e TestResponsiveEmptyPickTakesNoSlot: one gap before the visible wide variant at 1000px. After a live resize to 300px, one gap between the siblings. With the cancel disabled it fails: "leaves 39.2px … want one gap (19.6px)".
  • go test -race ./..., make e2e, both vets

Following the Empty fix in #36, a Responsive whose visible variant is
Empty still took a slot: in the TUI a blank line plus a gap on each
side, in the browser a zero-height wrapper with a gap on each side.

TUI: a Box drops children whose Responsive picks an empty variant at
the width they were given (after rendering them, so their picks stay
recorded for the focus ring), re-checking after a wrap collapse.

Browser: the wrapper must stay a box for its container queries, and
those cannot style the wrapper itself. In a gapped Column, a Responsive
with an Empty variant now carries a per-instance rule that cancels one
gap with a negative end margin while the wrapper is flagged empty, and
the renderer keeps the flag current with a ResizeObserver, which runs
after layout and before paint.

In a Row the browser wrapper still reserves its widest breakpoint's
width; that existing limitation is now documented in the README.
@archlemon
archlemon merged commit 0ae09d1 into main Nov 28, 2026
2 checks passed
@archlemon
archlemon deleted the fix/responsive-empty-slot branch November 28, 2026 10:46
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