You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature] Component previews in nsgo dev: show one component with fixture state, rebuilt on save, without restarting the app #659
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.
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.
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.
Activity
houko commentedon Nov 18, 2026
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.
houko commentedon Nov 20, 2026
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
devimplementation builds one project package and starts target-specific sessions, so a partial-previewflag 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.