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

No 👏 more 👏 server 👏 restarts 👏 on 👏 config 👏 changes #4578

Merged
merged 22 commits into from
Sep 9, 2022

Conversation

bholmesdev
Copy link
Contributor

@bholmesdev bholmesdev commented Aug 31, 2022

Changes

  • You heard right. Restart the dev server whenever configs are added, updated, or removed 🥳
  • Add restartInFlight flag to avoid clobbering when saving multiple times in a row
  • When a --config is specified, only watch changes on that file. Otherwise, watch for any new astro.config.* files in the project root. Yes, this means your server reloads when you swap file extensions!

About that writeFile call...

All good PRs have some spice: When a config file changes, write the config contents to temporary file at the project root with a unique timestamp, and quickly delete once the config is resolved.

Proload uses a native ESM import to resolve mjs and js configs, which is great... until the file contents change. Re-importing a file in Node will not get the file's up-to-date contents; once a file is imported in an application, the contents are cached as long as the process is running. This approach writes to a new file path so Node will think it's a new import every time. This is informed by Vite's ESM loader, which does a similar write-read-then-delete strategy.

I also considered writing to an internal node_modules/.astro directory instead of the project root. However, managing the "if this directory exists..." logic and relying on node_modules being present felt like unneeded overhead. This temporary file only appears briefly during development (not production), and will be removed whenever an error in thrown during config resolution (see finally block). Vite's comparable PR also writes to the project root for reference.

Testing

TODO? Is it worth an E2E test?

Docs

TODO: check if "restart the server" recs are mentioned in the docs

@changeset-bot
Copy link

changeset-bot bot commented Aug 31, 2022

🦋 Changeset detected

Latest commit: 67e22bd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
astro Minor
@e2e/astro-component Patch
@e2e/error-cyclic Patch
@e2e/error-react-spectrum Patch
@e2e/error-sass Patch
@e2e/errors Patch
@e2e/hydration-race Patch
@e2e/lit-component Patch
@e2e/preact-component Patch
@e2e/react-component Patch
@e2e/solid-component Patch
@e2e/solid-recurse Patch
@e2e/svelte-component Patch
@e2e/e2e-tailwindcss Patch
@e2e/ts-resolution Patch
@e2e/third-party-astro Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Aug 31, 2022
Comment on lines +525 to +533
optimizeDeps: { entries: [] },
clearScreen: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the screen refreshes with a warning statement on our Vite server fallback. entries prevents cache warnings, and clearScreen: false preserves output!

configFlagPath && normalizePath(configFlagPath) === normalizePath(changedFile)
: // Otherwise, watch for any astro.config.* file changes in project root
new RegExp(
`${normalizePath(resolvedRoot)}.*astro\.config\.((mjs)|(cjs)|(js)|(ts))$`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about .mts and .cts. j/k

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Therapist: cts doesn't exist in the docs, it can't hurt you.
cts:

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yas 👏

@bluwy
Copy link
Member

bluwy commented Sep 1, 2022

Actually it also looks like windows tests are failing somehow 🥲

@bluwy bluwy self-requested a review September 1, 2022 08:07
@bholmesdev bholmesdev force-pushed the feat/no-more-dev-server-restarts branch from 3cb90e6 to 2d0f4ce Compare September 2, 2022 15:19
@natemoo-re natemoo-re force-pushed the feat/no-more-dev-server-restarts branch from 153acca to 1ef563a Compare September 2, 2022 20:26
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work Ben, this is awesome!

@natemoo-re
Copy link
Member

I added some better handling for invalid configs and cleaned up the messages a little bit!

@natemoo-re natemoo-re added the semver: minor Change triggers a `minor` release label Sep 7, 2022
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just circling back to approve this again! Should be good to merge as soon as we're ready for the next minor release.

@bholmesdev
Copy link
Contributor Author

bholmesdev commented Sep 7, 2022

Update: both of these are addressed!

@natemoo-re actually needs a couple more things:

  1. Flip the steps of astro add to install deps before updating the config. Otherwise, running astro add will explode your dev server on uninstalled deps actually, it shouldn't fully explode after your change. But you'll need to force-save your config to force a restart.
  2. Update docs to remove "restart server" warnings

Both top priority tomorrow morning for me 👍

@bholmesdev bholmesdev force-pushed the feat/no-more-dev-server-restarts branch from 7610862 to 67e22bd Compare September 8, 2022 17:16
@bholmesdev bholmesdev requested a review from a team as a code owner September 8, 2022 17:16
@github-actions github-actions bot added pkg: lit Related to Lit (scope) pkg: preact Related to Preact (scope) pkg: react Related to React (scope) pkg: solid Related to Solid (scope) pkg: svelte Related to Svelte (scope) pkg: vue Related to Vue (scope) pkg: integration Related to any renderer integration (scope) labels Sep 8, 2022
@@ -469,7 +466,7 @@ const imageUrl = 'https://www.google.com/images/branding/googlelogo/2x/googlelog
```

## Troubleshooting
- If your installation doesn't seem to be working, make sure to restart the dev server.
- If your installation doesn't seem to be working, try restarting the dev server.
Copy link
Contributor Author

@bholmesdev bholmesdev Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tagging @sarah11918 from my docs PR earlier. Using this verbage now!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, @bholmesdev! 🥳

@matthewp matthewp merged commit c706d84 into main Sep 9, 2022
@matthewp matthewp deleted the feat/no-more-dev-server-restarts branch September 9, 2022 15:58
@astrobot-houston astrobot-houston mentioned this pull request Sep 9, 2022
@bluwy bluwy mentioned this pull request Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope) pkg: lit Related to Lit (scope) pkg: preact Related to Preact (scope) pkg: react Related to React (scope) pkg: solid Related to Solid (scope) pkg: svelte Related to Svelte (scope) pkg: vue Related to Vue (scope) semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants