Repository navigation
Description
Context
On a Go change, nsgo dev builds the app again and, once the build succeeds, stops the running app and starts the new binary (cmd/nsgo/dev.go:157-159 on main at 7ec1e19: progress.done(...), stop(), then s.start). On the native targets that means the window closes and a new one opens wherever the app's first window opens by default. Nothing carries over: the new process gets only NSGO_DEV_SERVER and NSGO_DEV_TOKEN (devEnv, dev.go:727), the dev client (internal/dev/client.go) saves nothing before it goes, and neither base.NewNav's stack nor the window frame is restored.
A Go change cannot be swapped into a running process (TSX changes already update in place, tsx/bundler.CompileHot), so restarting is expected. The problem is that the restart is visible as a different window:
- A window the developer placed beside the editor, tiled to half the screen, put in a macOS full-screen Split View, a Stage Manager set or a Windows Snap group disappears, and the new one opens somewhere else and outside that arrangement. Every save means putting the window back by hand.
- The app restarts on its first page, so a screen several pages deep has to be navigated to again after each change.
Measured on a 12-core Apple M4 Pro (macOS 27.2, Go 1.27.3, other builds running, load average 40–230), from saving a Go file to the new process starting:
| App | Runs | Save → restarted |
|---|---|---|
examples/hello |
3 | 1.6 s, 2.8 s, 2.7 s |
examples/gallery (115 files in main) |
5 | 9.0 s, 28.6 s, 20.0 s, 18.2 s, 11.7 s |
With -toolexec timing the go tools under nsgo dev, a gallery rebuild compiled only main (5.8–6.8 s) and linked (1.2–7.0 s); about 4 s more was spent outside the compiler and linker (catalogs, package listing, then macSession removing and rebuilding the whole .app and signing it, dev.go:745-747, not timed separately). So a restart is seconds long, and losing the window's place on top of that is what makes the Go loop feel much worse than the TSX one.
Why it matters
The reason to run a native target in dev is to see the app as it ships, next to the code. Keeping the window where the developer put it is what makes a restart feel like a refresh, as a browser tab does when a page reloads; it costs nothing in release builds, since it only concerns nsgodev builds and the tool.
Proposal
- Hand the window over instead of closing it. Before stopping the old app,
nsgo devasks it (over the dev server connection it already has) for each open window's screen, frame, full-screen state and, with an opt-in, the app's navigation state. The new process opens its windows hidden at those frames, shows them once their first frame is drawn, and only then is the old process stopped, so there is no gap and no jump. This covers ordinary placement, edge tiling on macOS 15+ and Windows Snap to a side, which are frames. - Restore where the app was. A dev-only hook (for example
core.DevKeep(cx, key, &value)or the nav stack taking part automatically) lets state that is serializable survive a dev restart; release builds compile it out. - Keep the window itself across restarts, as a separate, larger step. Arrangements that are about window identity rather than frame — macOS Split View, Stage Manager sets, Windows Snap groups — cannot be rejoined by a new window through public API. Only a window that outlives the app process keeps them: a dev-only host process owns the window and the app process renders into it (on macOS an IOSurface or layer hosting, compiled only into
nsgodevbuilds) with input, IME, menus and accessibility forwarded. Note that reloading the app's code in one process with Go'spluginis not an option: native builds areCGO_ENABLED=0(cmd/nsgo/build.go:716,:766,:787),pluginneeds cgo and has no Windows support. - Make the rebuild itself cheaper where
nsgo devadds to it: update the.appin place rather thanos.RemoveAlland a full rebuild and signature each time.
Acceptance
- After a Go change under
nsgo devon macOS, Windows and Linux, the app's windows reappear with the same screen, frame and full-screen state, without a window-sized gap between the old and the new one. - A value an app registers with the dev-only hook, and the nav stack, survive a dev restart; release builds contain none of it.
- (Step 3) On macOS, a window in a full-screen Split View stays in it across a Go change.
- Platforms: macOS, Windows, Linux (
nsgo dev -target native) - NSGo: main at 7ec1e19 (2026-11-18)
- Development machine: macOS 27.2 (Apple M4 Pro, 12 cores), Go 1.27.3
Activity
houko commentedon Nov 18, 2026
Related: #660 proposes hot-swapping literal-only edits (sizes, colors, text) in the running app without a rebuild. Together they split the Go edit loop: literal edits in milliseconds (#660), structural edits rebuilt and restarted with the window and state kept (this issue), single components in fixture states (#659).
houko commentedon Nov 20, 2026
I audited the current native dev restart flow.
nsgo devstill stops the old process and starts a fresh native session, with no frame/navigation handoff. A complete fix needs a dev-server protocol for window state, startup ordering, platform-specific fullscreen/Snap behavior, and a serializable navigation-state contract. I left the issue open without a partial change that would only restore ordinary frames while claiming the broader acceptance criteria.houko commentedon Nov 22, 2026
I audited #658 against
origin/mainat091984681and the live child PRs.internal/platform/macos/dev_window_frame.gorecords the last normal frame and restores it before layout.The parent acceptance remains incomplete. Current work still does not provide navigation-state restoration, secondary-window handoff, a seamless old/new process overlap, identity-preserving macOS Split View or Windows Snap-group handoff, or the proposed dev-only serializable state hook. I am leaving #658 open for those remaining parts and keeping the child PRs separate.