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: handle postcss load unhandled rejections #18886

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
4 changes: 4 additions & 0 deletions packages/vite/bin/vite.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ if (!import.meta.url.includes('node_modules')) {
// only available as dev dependency
await import('source-map-support').then((r) => r.default.install())
} catch {}

process.on('unhandledRejection', (err) => {
throw new Error('UNHANDLED PROMISE REJECTION', { cause: err })
})
Comment on lines +10 to +13
Copy link
Member Author

@sapphi-red sapphi-red Dec 5, 2024

Choose a reason for hiding this comment

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

This won't catch the reported case. But this will catch a similar issue in some cases.

Copy link
Member

Choose a reason for hiding this comment

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

Is it useful to add this by default in the CLI? Shouldn't we preserve the unhandled rejections error as is? Re-throwing the error seems to only wrap it around

Copy link
Member Author

Choose a reason for hiding this comment

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

https://github.com/vitejs/vite/pull/18886/files/1cc739eb0cd1be50d11b934a7502d8f646fca4de#diff-d41df705e208c4e8871565005d95b6fd86ba6eb17c826a225715203ba0c31a28R5
This only happens when developing Vite core or linking to local, so I think it's fine.

Re-throwing the error seems to only wrap it around

If I didn't test it wrongly, when an error is thrown inside a event handler, Node exits the process.

Copy link
Member

Choose a reason for hiding this comment

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

This only happens when developing Vite core or linking to local, so I think it's fine.

Ah ok I didn't notice that.

If I didn't test it wrongly, when an error is thrown inside a event handler, Node exits the process.

Ah so when developing locally we want to forcefully exit the process, mostly for debugging I guess? I think overall that makes sense to me then. Thanks

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep!

}

global.__vite_start_time = performance.now()
Expand Down
15 changes: 11 additions & 4 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ export function cssPlugin(config: ResolvedConfig): Plugin {

// warm up cache for resolved postcss config
if (config.css?.transformer !== 'lightningcss') {
resolvePostcssConfig(config)
resolvePostcssConfig(config).catch(() => {
/* will be handled later */
})
}

return {
Expand Down Expand Up @@ -1696,9 +1698,14 @@ async function resolvePostcssConfig(
return null
})
// replace cached promise to result object when finished
result.then((resolved) => {
postcssConfigCache.set(config, resolved)
})
result.then(
(resolved) => {
postcssConfigCache.set(config, resolved)
},
() => {
/* keep as rejected promise, will be handled later */
},
)
}

postcssConfigCache.set(config, result)
Expand Down
Loading