From 2c6484a4c34e86b8a26342a48986da26768de27b Mon Sep 17 00:00:00 2001 From: Kendell Date: Fri, 13 Feb 2026 14:16:22 -0800 Subject: [PATCH] fix: wait to bind shortcuts (#15508) * fix: wait to bind shortcuts * add changeset * follow changeset style guidelines --- .changeset/big-laws-dig.md | 5 ++++ packages/astro/src/core/dev/dev.ts | 1 + packages/astro/src/core/dev/restart.ts | 40 +++++++++++++------------- 3 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 .changeset/big-laws-dig.md diff --git a/.changeset/big-laws-dig.md b/.changeset/big-laws-dig.md new file mode 100644 index 000000000000..27734e093d7d --- /dev/null +++ b/.changeset/big-laws-dig.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes behavior when shortcuts are used before server is ready diff --git a/packages/astro/src/core/dev/dev.ts b/packages/astro/src/core/dev/dev.ts index 904a7b1a95ca..1b6fb8abd930 100644 --- a/packages/astro/src/core/dev/dev.ts +++ b/packages/astro/src/core/dev/dev.ts @@ -116,6 +116,7 @@ export default async function dev(inlineConfig: AstroInlineConfig): Promise void; restarted: () => Promise; } @@ -158,6 +159,25 @@ export async function createContainerWithAutomaticRestart({ let restart: Restart = { container: initialContainer, + bindCLIShortcuts() { + const customShortcuts: Array = [ + // Disable default Vite shortcuts that don't work well with Astro + { key: 'r', description: '' }, + { key: 'u', description: '' }, + { key: 'c', description: '' }, + ]; + + customShortcuts.push({ + key: 's', + description: 'sync content layer', + action: () => { + globalContentLayer.get()?.sync(); + }, + }); + restart.container.viteServer.bindCLIShortcuts({ + customShortcuts, + }); + }, restarted() { return restartComplete; }, @@ -210,26 +230,6 @@ export async function createContainerWithAutomaticRestart({ await handleServerRestart('', restart.container.viteServer); } }; - - // Set up shortcuts - - const customShortcuts: Array = [ - // Disable default Vite shortcuts that don't work well with Astro - { key: 'r', description: '' }, - { key: 'u', description: '' }, - { key: 'c', description: '' }, - ]; - - customShortcuts.push({ - key: 's', - description: 'sync content layer', - action: () => { - globalContentLayer.get()?.sync(); - }, - }); - restart.container.viteServer.bindCLIShortcuts({ - customShortcuts, - }); } setupContainer(); return restart;