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(#2981): keeps astro preview server alive #3004

Merged
merged 3 commits into from
Apr 6, 2022
Merged

Conversation

tony-sull
Copy link
Contributor

Changes

Fixes a bug that was preventing the astro preview server from staying alive

Testing

Tested locally

Docs

Bug fix only

@changeset-bot
Copy link

changeset-bot bot commented Apr 6, 2022

🦋 Changeset detected

Latest commit: 1673c71

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

This PR includes changesets to release 1 package
Name Type
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 Apr 6, 2022
@matthewp
Copy link
Contributor

matthewp commented Apr 6, 2022

Hm, I'm not sure about this. I don't love the idea of returning a promise that never results as a way to prevent the server from closing. Look at the code for preview it doesn't look like the server should be closing when the function completes. Why is it doing so?

@caioferrarezi
Copy link
Contributor

caioferrarezi commented Apr 6, 2022

Hi, @tony-sull!

I was looking for a solution based on what @matthewp has said and I found this promise chaining added in the main process when the CLI is called https://github.com/withastro/astro/blame/a68885c0d62018b74d1a5c30395d237829b72c61/packages/astro/astro.js#L100

It seems like the .then(() => process.exit(0)) is killing the node environment when the preview's server promise resolution is executed here https://github.com/withastro/astro/blob/main/packages/astro/src/core/preview/index.ts#L109

Hope it may help!

Thanks!

@tony-sull
Copy link
Contributor Author

Hm, I'm not sure about this. I don't love the idea of returning a promise that never results as a way to prevent the server from closing. Look at the code for preview it doesn't look like the server should be closing when the function completes. Why is it doing so?

For astro preview the CLI was returning a promise that only tracked when the server was opened so it killed the process right away

I did find a cleaner solution here though, wrapped the server's close and error events in a promise so the CLI is actually going to track the server instance itself

@tony-sull tony-sull requested a review from matthewp April 6, 2022 14:45
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.

Nice solution! LGTM.

@tony-sull tony-sull merged commit 9724d84 into main Apr 6, 2022
@tony-sull tony-sull linked an issue Apr 6, 2022 that may be closed by this pull request
1 task
This was referenced Apr 6, 2022
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* fix(withastro#2981): keeps  server alive

* chore: adding changeset

* keep alive until the 'close' or 'error' event fires
@bluwy bluwy deleted the fix/astro-preview branch October 8, 2024 05:56
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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 BUG: astro preview stopped working
4 participants