Skip to content

PostCSS: Improve error recovery #17754

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

Merged
merged 1 commit into from
Apr 25, 2025
Merged

Conversation

philipp-spiess
Copy link
Member

@philipp-spiess philipp-spiess commented Apr 23, 2025

Closes #17295

This commit addresses an issue where the PostCSS plugin would get stuck in an error state when processing files with e.g. invalid @apply directives.

This change prevents the PostCSS plugin from getting stuck in an error states particularly when the error happened inside an @imported CSS files (as these were not registered as dependencies correctly before).

Error overlays

Some frameworks (e.g. Angular 19 or Next.js) handle errors inside PostCSS transforms to render a nice error overlay. This works well and gives immediate feedback that something went wrong. However, even when dependencies are registered before an error is thrown, these frameworks will not consider changes to these dependencies anymore when an error occurs, as you can see in this Next.js example:

Screen.Recording.2025-04-23.at.14.42.16.mov

To avoid conditions where errors are not recoverable, this PR makes it so that these overlays will no longer show up in the app and only be logged to the output console. This will need follow-up upstream work before we can revisit this.

Test plan

@philipp-spiess philipp-spiess requested a review from a team as a code owner April 23, 2025 12:49
@philipp-spiess philipp-spiess force-pushed the fix/postcss-error-restoration branch 3 times, most recently from f41a425 to 5c76efd Compare April 23, 2025 13:08
// in some situations so we instead log the error and continue with an empty stylesheet.
console.error(error)
root.removeAll()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd love if we could re-organize the code somehow so we're not wrapping 200 lines in a try/catch but this is probably fine for now.

ps you should be able to move the createCompiler() definition out of it

@philipp-spiess philipp-spiess force-pushed the fix/postcss-error-restoration branch from 5c76efd to 5083222 Compare April 24, 2025 10:28
This commit addresses an issue where the PostCSS plugin would get stuck in an error state
when processing files with invalid @apply directives, particularly affecting Angular 19
applications. The fix:

1. Adds error recovery in the @apply directive processor to gracefully handle errors
2. Prevents the PostCSS plugin from getting stuck in an error state after encountering
   an invalid @apply directive
@philipp-spiess philipp-spiess force-pushed the fix/postcss-error-restoration branch from 5083222 to 1802309 Compare April 24, 2025 10:33
@philipp-spiess philipp-spiess merged commit 52000a3 into main Apr 25, 2025
7 checks passed
@philipp-spiess philipp-spiess deleted the fix/postcss-error-restoration branch April 25, 2025 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Angular 19 cannot automatically recover using @apply with Tailwind CSS 4
3 participants