Skip to content

feat(core)!: shrink growing boxes and scroll views by default - #2739

Open
oneo-me wants to merge 2 commits into
mainfrom
agiox/fix-ui-scroll
Open

oneo-me wants to merge 2 commits into
mainfrom
agiox/fix-ui-scroll

Conversation

@oneo-me

@oneo-me oneo-me commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Screens written the obvious way stop scrolling: FlexShrink defaulted to 0, so any core.View between the window and a core.Scroll or core.List, such as core.View{Style: core.Style{FlexGrow: 1}} or a bare wrapper, grew to the list's full height and the list had nothing left to scroll. Three apps hit it while migrating, and NSGo's own examples/previews, the preview host, ui/filepicker and base/dock carried the same mistake.

Now a box that grows, a Scroll or List along its scroll axis, and each box around one that sets no size on that axis shrink by default, so a list scrolls however deep it sits. Every other box keeps its size, a Scroll's content included, so headers, tabs, toolbars and sidebars beside a list are not squeezed: shrinking everything, as CSS does, squashed them, since NSGo has no automatic minimum sizes to stop it.

Breaking: core.Style.FlexShrink becomes a core.FlexShrink set with core.Shrink(n) or core.NoShrink, so the old FlexShrink: 0 and FlexShrink: 1 no longer compile instead of silently changing meaning. Apps write core.NoShrink for 0 where a growing or scrolling box must keep its size, core.Shrink(n) for other factors, and drop FlexShrink: 1 beside FlexGrow: 1.

  • core/layout.go resolves the default (defaultFlexShrink), with a scroll-axis bitmask kept per node for the dirty subtree before each layout (syncScrollAxes); reparenting drops cached layout styles.
  • Every FlexShrink in the repository is migrated, Tailwind's shrink-* and TSX's flexShrink included.
  • The web host now fills the window when it mounts on the page's body, whose height was 0 without page CSS (separate commit).
  • Docs: docs/architecture/core.md, layout.md in every language, skills/nsgo/SKILL.md.

The changelog fragment uses ### Breaking, which #2736 adds: merge #2736 first, then this after a rebase, or tools/changelog check fails.

Targets

  • Shared code (core, base, ui, tsx, the nsgo tool)
  • macOS
  • iOS
  • tvOS
  • watchOS
  • Android
  • Windows
  • Linux
  • Web
  • Mini programs
  • Docs or website only

Screenshots

The gallery's pages lay out as on main at desktop and phone sizes, compared view by view for overflowing or squashed boxes, except Plot's last x-axis label, which now stays inside the plot instead of running past its end.

Verification

Checklist

  • The title is a Conventional Commit, such as fix(linux): keep the caret after a paste; a squash merge uses it as the commit subject.
  • Docs whose facts change are updated, and a capability users can see has a line in a changelog.d/ fragment, not in CHANGELOG.md.
  • New third-party code, assets and dependencies name their source and license.

🤖 Claude Opus 5.5

🤖 Generated with Claude Code

oneo-me and others added 2 commits November 28, 2026 20:33
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A box that grows, a Scroll or List along its scroll axis and each box
around one that sets no size on that axis now shrink by default, so a
list or scroll view scrolls however deep it sits instead of stretching
the boxes around it past the window. Other boxes, a Scroll's content
included, keep their size.

BREAKING CHANGE: core.Style.FlexShrink is a core.FlexShrink instead of
a float32. Write FlexShrink: core.NoShrink for FlexShrink: 0 where a
growing or scrolling box must keep its size, FlexShrink: core.Shrink(n)
for any other factor, and drop FlexShrink: 1 beside FlexGrow: 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oneo-me
oneo-me requested a review from houko November 28, 2026 12:34
@oneo-me

oneo-me commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

@houko could you review this one with me? It is a key change: the default layout locks scrolling as soon as any box sits between the window and a list, which every app migrating to NSGo has hit, and this fixes it at the root. But it breaks users hard: Style.FlexShrink changes type, so every app that sets it stops compiling, and boxes that grow or wrap a scroll view now shrink where they used to overflow, which can move layouts that never set FlexShrink. Please look especially at whether the default rule (defaultFlexShrink in core/layout.go) is the right line to draw, and whether the break is worth it or should land differently, such as behind a transition.

🤖 Claude Opus 5.5

@houko houko left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach is right and I could not find a case where the new defaults lay out wrongly. I traced the invalidation paths of syncScrollAxes / defaultFlexShrink: a parent's Direction flip and a Scroll.Horizontal change drop the children's cached styles, place and Holder.show call dropLayoutStyles, hoisted roots (modals, overlays, accessories, PiP) all go through layoutRoot, which syncs first, and relayoutBoundaries syncs before Relayout. A boundary has point sizes on both axes, so it never exposes a scroll axis and cannot leave its parent's default stale. Requesting changes for the CI failures and the missing tests.

Blocking

  1. Go formatting fails on tsx/stylekeys_test.go: the map keys need realigning after the type change. gofmt -w tsx/stylekeys_test.go.
  2. test-suite (core) fails on TestRepositoryFragments because of ### Breaking; expected until #2736 lands, as the description says. Keep the merge order.

Should change

  1. Tests cover only the static nesting. core/layout_test.go adds one test, and the part most likely to regress is the cached bitmask on incremental updates, which layoutDirty pruning skips. Each of these should assert that the list still scrolls after the update:
    • a parent's Direction switching between row and column;
    • Scroll.Horizontal toggling;
    • a wrapper around a List moved to another parent;
    • a wrapper around a List inside a modal or overlay;
    • a Scroll mounted into, and removed from, a tree that has already been laid out.
  2. layout.Boundary is relaxed without a mention. A box with point sizes and a nonzero shrink now counts as a relayout boundary when both MinSizes are points. With no automatic minimum sizes nothing inside can change its size, so I believe it is correct, but it changes incremental layout on its own. Please say so in the description and add a test: such a boundary keeps the right size after a sibling changes.
  3. FlexShrink.Value() returns 0 when unset, while the factor in effect may be 1. A tool that reads it, such as an inspector or a serializer, reports the wrong number. Either document it as the explicit factor only, or drop Value() from the exported API.

Worth noting

  1. A growing box now shrinks by default. In a column, a FlexGrow: 1 box whose content is taller than the window used to grow and push the following siblings off screen; now it shrinks to fit and its content overflows onto them, a footer for example. The breaking note says growing boxes shrink, but the migration text should name this consequence: such content needs Overflow or a Scroll around it.
  2. When mounting on body, the web host now sets inline width/height: 100% on html and body and margin: 0 on body, which overrides a page's own CSS for them. It is a separate commit with a different reach from the rest of the PR; consider splitting it out.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants