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

vite-ssg (yargs) does not terminate if setInterval is used #113

Closed
cimchd opened this issue Oct 6, 2021 · 3 comments · Fixed by #121
Closed

vite-ssg (yargs) does not terminate if setInterval is used #113

cimchd opened this issue Oct 6, 2021 · 3 comments · Fixed by #121

Comments

@cimchd
Copy link
Contributor

cimchd commented Oct 6, 2021

I have a project that has a page included with a counter component (counting each second down until an event starts) that uses setInterval. Yargs seems to wait for the interval to end, which does not happen.

I think there could be similiar situations in websites where some components provide code that does not finish.
In my project I have a ci pipleine that waits for vite-ssg to finish in order to do the next build steps.

A quick fix for me was to add process.exit(0) to the onFinished option:

// vite.config.js
export default {
  // ...
  ssgOptions: {
    onFinished() {
      process.exit(0);
    },
  }
}

I am just wondering if this should be the default behaviour, to call process.exit(0) after the build has finished. It took me quite some time to find the reason why vite-ssg did not terminate the process.

If this should not be the default behaviour, maybe we can provide a warning?

@antfu
Copy link
Member

antfu commented Oct 7, 2021

You should not use timers in SSR/SSG (use if (typeof window !== 'undefiend') to them).

We could have a timeout mechanism like Nuxt to exist the process when the bundler finished but process handing for certain minutes. PR welcome.

@cimchd
Copy link
Contributor Author

cimchd commented Oct 25, 2021

I can provide such a PR. :-)

But do you really want to wait some minutes? Personally I prefer a shorter time, like 10 seconds or maybe up to 30 seconds. At the moment I can't think about a case where it would be better to wait longer.

@antfu
Copy link
Member

antfu commented Oct 25, 2021

Sure. like 15 seconds sounds reasonable - or we can adjust it based on feedback anyway. Looking forward to your PR!

cimchd added a commit to cimchd/vite-ssg that referenced this issue Oct 26, 2021
antfu added a commit that referenced this issue Oct 28, 2021
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants