summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/proud-singers-call.md5
-rw-r--r--packages/astro/src/core/dev/container.ts16
2 files changed, 20 insertions, 1 deletions
diff --git a/.changeset/proud-singers-call.md b/.changeset/proud-singers-call.md
new file mode 100644
index 000000000..8b882fb95
--- /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 0102a87cd..9e381d76d 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.