0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-17 22:44:24 -05:00

fix(astro): do not open new tab when saving config files (#11456)

This commit is contained in:
Ricky Chon 2024-07-16 12:50:51 -04:00 committed by GitHub
parent 16ed760f99
commit 17e048de0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes `astro dev --open` unexpected behavior that spawns a new tab every time a config file is saved

View file

@ -56,9 +56,23 @@ export async function createContainer({
base,
server: { host, headers, open: serverOpen },
} = settings.config;
// serverOpen = true, isRestart = false
// when astro dev --open command is run the first time
// expected behavior: spawn a new tab
// ------------------------------------------------------
// serverOpen = true, isRestart = true
// when config file is saved
// expected behavior: do not spawn a new tab
// ------------------------------------------------------
// Non-config files don't reach this point
const isServerOpenURL = typeof serverOpen == 'string' && !isRestart;
const isServerOpenBoolean = serverOpen && !isRestart;
// Open server to the correct path. We pass the `base` here as we didn't pass the
// base to the initial Vite config
const open = typeof serverOpen == 'string' ? serverOpen : serverOpen ? base : false;
const open = isServerOpenURL ? serverOpen
: isServerOpenBoolean ? base : false;
// The client entrypoint for renderers. Since these are imported dynamically
// we need to tell Vite to preoptimize them.