Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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/proud-singers-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes `astro dev --open` unexpected behavior that spawns a new tab every time a config file is saved
16 changes: 15 additions & 1 deletion packages/astro/src/core/dev/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading