From 224110f307f382126a26fbc8061bc6d82c7b3ea7 Mon Sep 17 00:00:00 2001 From: Ricky Chon Date: Tue, 16 Jul 2024 12:50:51 -0400 Subject: [PATCH] fix(astro): do not open new tab when saving config files (#11456) --- .changeset/proud-singers-call.md | 5 +++++ packages/astro/src/core/dev/container.ts | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .changeset/proud-singers-call.md diff --git a/.changeset/proud-singers-call.md b/.changeset/proud-singers-call.md new file mode 100644 index 0000000000..8b882fb955 --- /dev/null +++ b/.changeset/proud-singers-call.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes `astro dev --open` unexpected behavior that spawns a new tab every time a config file is saved diff --git a/packages/astro/src/core/dev/container.ts b/packages/astro/src/core/dev/container.ts index 0102a87cd0..9e381d76df 100644 --- a/packages/astro/src/core/dev/container.ts +++ b/packages/astro/src/core/dev/container.ts @@ -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.