feat: add closeServer and closePreviewServer hooks - #23110
Conversation
75fd96b to
92d7629
Compare
|
Would it be possible to extract the signal-exit change in a separate PR? |
92d7629 to
c0c3713
Compare
I've updated this PR to only add the new hooks and I have a separate PR to use signal-exit that I can open once this one's merged. One thing to flag is that a throwing |
The reason why the config-change prevents the unhandled rejection is to avoid the process exit happening when saving a intermediate config file. I think it's ok to keep the difference for this PR. But maybe we should align it. |
Fixes #22913
Description
Adds two new plugin hooks that let plugins run cleanup when a dev or preview server shuts down:
closeServer(server, { reason })— called when the dev server closes. reason is 'restart' (server is being replaced by a restart) or 'close' (server is shutting down for good).closePreviewServer(server)— called when the preview server closes. No reason, since preview servers never restart.Notes
Promise.all. This matches the globalconfigResolved()hook and the per-environmentcloseWatcher()hook. It may be preferable to usePromise.allSettledbut, if so, this behaviour should be aligned across these hooks. Currently a throwingcloseServer()hook can lead to unhandled rejections and a dormant server instance.