Skip to content

Commit

Permalink
fix: handle postcss load unhandled rejections (#18886)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Dec 5, 2024
1 parent 2b5926a commit d5fb653
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
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 })
})
}

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

0 comments on commit d5fb653

Please sign in to comment.