Skip to content

[Feature] Component previews in nsgo dev: show one component with fixture state, rebuilt on save, without restarting the app #659

Closed

Description

@houko

Context

A Go change under nsgo dev rebuilds and restarts the whole app (cmd/nsgo/dev.go:157-159), which for examples/gallery took 9–28 s per save on a 12-core Apple M4 Pro under load (#658), and the app restarts on its first page. When the work is one component — a row, a dialog, a chart — most of that is spent linking and starting an app around it and navigating back to it.

examples/previews shows the docs' component examples on the website (a launch parameter picks a demo), but it is not something an app's developer points at their own components while working.

Why it matters

SwiftUI previews, Jetpack Compose previews and Storybook let a developer iterate on one component in the states that matter (empty, loading, error, long text, right-to-left, dark) without reaching it through the app. In NSGo a component is a Go function of a scope, so a preview needs no runtime support: it needs a small host, built with the developer's package, that renders the chosen component with fixture state. Because the state comes from the fixture, a restart loses nothing.

Proposal

  • A way to declare previews next to components, for example functions named PreviewXxx(cx *core.Scope) core.Node in _preview.go files or a nsgo.Preview("name", fn) registration under a nsgopreview build tag, so they never reach a release build.
  • go tool nsgo dev -preview ./path/to/pkg builds a small host linking only that package and its dependencies, lists its previews and shows the chosen ones (several at once, in a grid, with locale, theme, size and right-to-left switches), rebuilding on save as dev does. Linking a small host instead of the app keeps the rebuild short.
  • The same previews feed nsgotest screenshot tests, so a preview is also a visual test.

Acceptance

  • A package with PreviewXxx functions can be shown with nsgo dev -preview on the native target and the web, and a save rebuilds and shows the change without navigating.
  • Preview code is absent from nsgo build output.
  • Previews can be rendered in each locale and theme the app declares.

  • Platforms: all dev targets
  • NSGo: main at 7ec1e19 (2026-11-18)
  • Development machine: macOS 27.2 (Apple M4 Pro, 12 cores), Go 1.27.3

Activity

  1. houko commented on Nov 18, 2026

    @houko
    CollaboratorAuthor

    Related: #660 (literal-only edits hot-swapped without a rebuild) and #658 (structural edits restart with the window and state kept). Previews cover iterating on one component away from the app.

  2. self-assigned this
    on Nov 20, 2026
  3. houko commented on Nov 20, 2026

    @houko
    CollaboratorAuthor

    Reviewed against the current development architecture. This is a worthwhile feature, but the proposal spans preview discovery and build tags, a separate host binary, native and web session integration, hot rebuilds, locale/theme/RTL controls, and screenshot-test plumbing. The current dev implementation builds one project package and starts target-specific sessions, so a partial -preview flag would not satisfy the acceptance criteria or prove preview code is excluded from release builds. I am leaving the issue open for a dedicated preview-host design.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions