Improve css-loader cache to avoid failing build with nextjs and webpack#275
Merged
Jan Nicklas (jantimon) merged 1 commit intomainfrom Feb 12, 2025
Merged
Conversation
Jan Nicklas (jantimon)
approved these changes
Feb 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After migrating more and more styled-components usages to next-yak, we started to experience failed nextjs builds (next build). The build ended without any error message and with a success status code, which is quite strange. After some time analyzing the issue, we were able to relate the issue to the parsed files cache within the css-loader.
Initially, the cache stored the promise resolving and parsing a module and its dependencies. A parallel request resolving the same module would, therefore, await the same promise and not load the module again. This likely led to a deadlock, or it has just exceeded the maximum number of concurrent loader executions.
Removing the cache solved the issue but slowed the build down quite a bit. With this PR, we change the cache to only cache the final result with the compromise of having the same module resolved more than once if requested simultaneously. Our performance test showed the exact same build time but without any failing builds.