Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/big-laws-dig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes behavior when shortcuts are used before server is ready
1 change: 1 addition & 0 deletions packages/astro/src/core/dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default async function dev(inlineConfig: AstroInlineConfig): Promise<DevS

// Start listening to the port
const devServerAddressInfo = await startContainer(restart.container);
restart.bindCLIShortcuts();
logger.info(
'SKIP_FORMAT',
msg.serverStart({
Expand Down
40 changes: 20 additions & 20 deletions packages/astro/src/core/dev/restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ interface CreateContainerWithAutomaticRestart {

interface Restart {
container: Container;
bindCLIShortcuts: () => void;
restarted: () => Promise<Error | null>;
}

Expand Down Expand Up @@ -158,6 +159,25 @@ export async function createContainerWithAutomaticRestart({

let restart: Restart = {
container: initialContainer,
bindCLIShortcuts() {
const customShortcuts: Array<vite.CLIShortcut> = [
// 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;
},
Expand Down Expand Up @@ -210,26 +230,6 @@ export async function createContainerWithAutomaticRestart({
await handleServerRestart('', restart.container.viteServer);
}
};

// Set up shortcuts

const customShortcuts: Array<vite.CLIShortcut> = [
// 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;
Expand Down
Loading