-
Notifications
You must be signed in to change notification settings - Fork 120
fix(dev): handle keyboard input before dev server is up + running #1546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b90f7e0
feat(dev): answer shortcuts before the server is up
danielroe 8a19b3f
fix(dev): stop a fork opening the browser again
danielroe ac21208
fix(dev): keep terminal replies out of the keys the panel reads
danielroe 0769e44
fix(dev): drop input the terminal buffered before anything was reading
danielroe d8cdf61
fix: hand stdin back to the key reader at first keystroke
danielroe 1a021da
chore: keep a right-aligned tag in place when scrubbing
danielroe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import type { Listener } from './listen' | ||
|
|
||
| export interface ShortcutContext { | ||
| /** The bound server, once there is one. */ | ||
| listener?: Listener | ||
| close: () => Promise<void> | ||
| restart?: () => void | Promise<void> | ||
| /** Remove the caches that make the next start cold, naming what went. */ | ||
| clearCaches?: () => Promise<string[]> | ||
| onReady: (callback: (address: string) => void) => void | ||
| } | ||
|
|
||
| /** What a started dev server contributes to a {@link ShortcutContext}. */ | ||
| interface ShortcutServer { | ||
| listener: Listener | ||
| close: () => Promise<void> | ||
| restart?: () => void | Promise<void> | ||
| onReady: (callback: (address: string) => void) => void | ||
| } | ||
|
|
||
| export interface DeferredShortcutContext { | ||
| context: ShortcutContext | ||
| attach: (server: ShortcutServer) => void | ||
| } | ||
|
|
||
| /** | ||
| * A context for shortcuts bound before the dev server exists, so the keyboard | ||
| * answers from the first frame. {@link ShortcutContext.listener} is undefined | ||
| * until {@link DeferredShortcutContext.attach}, and ready callbacks registered | ||
| * before then are forwarded to the server when it arrives. | ||
| */ | ||
| export function deferShortcutContext(options: Pick<ShortcutContext, 'clearCaches'> = {}): DeferredShortcutContext { | ||
| let server: ShortcutServer | undefined | ||
| let closing: Promise<void> | undefined | ||
| const pendingReady: Array<(address: string) => void> = [] | ||
|
|
||
| return { | ||
| context: { | ||
| clearCaches: options.clearCaches, | ||
| get listener() { | ||
| return server?.listener | ||
| }, | ||
| get restart() { | ||
| return server?.restart | ||
| }, | ||
| close: () => closing ??= server?.close() ?? Promise.resolve(), | ||
| onReady: (callback) => { | ||
| if (server) { | ||
| server.onReady(callback) | ||
| } | ||
| else { | ||
| pendingReady.push(callback) | ||
| } | ||
| }, | ||
| }, | ||
| attach: (started) => { | ||
| // A shutdown started before this existed had nothing to close. | ||
| if (closing) { | ||
| closing = closing.then(() => started.close()) | ||
| return | ||
| } | ||
| server = started | ||
| for (const callback of pendingReady.splice(0)) { | ||
| started.onReady(callback) | ||
| } | ||
| }, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: nuxt/cli
Length of output: 8448
🏁 Script executed:
Repository: nuxt/cli
Length of output: 42277
🏁 Script executed:
sed -n '460,510p' packages/nuxt-cli/src/commands/dev.tsRepository: nuxt/cli
Length of output: 1974
🏁 Script executed:
Repository: nuxt/cli
Length of output: 6373
🏁 Script executed:
rg -n -C 12 'function withSpinner|const withSpinner|export .*withSpinner' packages/nuxt-cli/src/utils packages/nuxt-cli/testRepository: nuxt/cli
Length of output: 2242
Close a server attached after shutdown starts.
setupSignalHandlerscan begin shutdown whileinitialize()is pending. The pre-attachcontext.close()resolves immediately, whileshutdownWithSpinnerperforms asynchronous work beforeprocess.exit(). If initialization finishes during that window,attach()installs a live server without invoking its gracefulclose()path. Track the close request and ensure a later attachment is closed before shutdown completes.🤖 Prompt for AI Agents