Repository navigation
Improve docs-builder serve reliability and startup speed - #2982
Conversation
The serve command had several regressions that made the local authoring workflow frustrating: editing docset.yml no longer reloaded properly, adding/removing/renaming files required a full restart, OpenAPI generation blocked startup, CTRL+C was slow to cancel, and the diagnostics HUD disappeared after the first file change. This fixes all of those issues and adds a quality-of-life improvement that preserves navigation tree state across live reloads. Configuration reload on file changes: - Add BuildContext.ReloadConfiguration() to re-read docset.yml from disk when config files or file structure changes, while skipping the expensive re-parse for simple markdown content edits. - Watch _docset.yml and toc.yml in addition to docset.yml and *.md so navigation structure changes are detected without a restart. - Preserve serve-mode feature flags (e.g. diagnostics panel) across configuration reloads. Lazy OpenAPI generation: - Move OpenAPI document generation out of the startup path so the server reaches "Now listening on" immediately instead of blocking on spec parsing. - Generate API references on-demand when the first /api/ request arrives, with change detection so specs are only regenerated when modified. Faster CTRL+C cancellation: - Wire a service-scoped CancellationTokenSource through the reload pipeline so in-flight reloads are cancelled promptly on shutdown, replacing the previous Cancel.None that caused hangs. Navigation state preservation (dev mode only): - Persist expanded/collapsed navigation tree state to sessionStorage so sections you had open stay open after a live reload, instead of collapsing back to only the current page's ancestors. - Gated behind the diagnostics panel presence check so it has zero impact on production builds. Made-with: Cursor
📝 WalkthroughWalkthroughThis pull request adds configuration reloading and lazy-loading of API references to the documentation builder. The Sequence Diagram(s)sequenceDiagram
participant Watcher as File Watcher
participant RGService as ReloadGeneratorService
participant RGState as ReloadableGeneratorState
participant BuildCtx as BuildContext
participant FileSystem as File System
Watcher->>RGService: File change detected<br/>(docset.yml/toc.yml)
RGService->>RGService: Reload(reloadConfiguration: true)
RGService->>RGState: ReloadAsync(ctx, reloadConfiguration: true)
RGState->>BuildCtx: ReloadConfiguration()
BuildCtx->>FileSystem: Load docset.yml & toc.yml
BuildCtx->>BuildCtx: Rebuild Configuration<br/>(preserve diagnostics)
RGState->>RGState: Regenerate documentation
RGState-->>RGService: Reload complete
sequenceDiagram
participant Client as HTTP Client
participant WebHost as DocumentationWebHost
participant RGState as ReloadableGeneratorState
participant FileSystem as File System
Client->>WebHost: GET /api/...
WebHost->>RGState: EnsureApiReferencesAsync(ctx)
RGState->>RGState: Check _apiReferencesStale flag
alt API references need regeneration
RGState->>FileSystem: Check if specs changed
RGState->>FileSystem: Regenerate /api/ artifacts
RGState->>RGState: Update spec timestamps<br/>Mark references fresh
end
RGState-->>WebHost: API references ready
WebHost->>FileSystem: Read index.html
WebHost-->>Client: Serve API documentation
Suggested labels
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Comment |
What changed
This PR fixes several regressions in
docs-builder serveand adds a quality-of-life improvement for anyone writing docs locally.Why this matters for writers
If you use
docs-builder serveday-to-day, you've probably hit these pain points:docset.ymldid nothing — you had to kill and restart the server to see navigation changes. Now it live-reloads automatically.toc.ymland_docset.yml.docs-builder serve.Technical summary
Configuration reload on file changes
BuildContext.ReloadConfiguration()to re-readdocset.yml/_docset.ymlfrom disk on config or structural file changes, while skipping the expensive re-parse for simple markdown content edits._docset.ymlandtoc.ymlto theFileSystemWatcherfilters.Lazy OpenAPI generation
EnsureApiReferencesAsync()method triggered by the first/api/request.Faster CTRL+C cancellation
CancellationTokenSourcethrough the reload/debounce pipeline, replacing the previousCancel.Nonethat caused in-flight reloads to ignore shutdown signals.Navigation state preservation (dev mode only)
sessionStorageso sections stay open across live reloads.Test plan
docs-builder serve, verify server starts and reaches "Now listening" without waiting for OpenAPI generation_docset.yml(e.g. comment out a file entry), verify navigation updates on reload.mdfile, verify it's reflected without restarttoc.ymlfile, verify navigation updates on reload/api/endpoint to trigger lazy OpenAPI generation, verify it worksMade with Cursor