Skip to content

fix: out of order cleanup with top-level await #898

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 2 commits into from
Mar 31, 2025

Conversation

erm410
Copy link
Contributor

@erm410 erm410 commented Feb 15, 2025

#729 happens because webpack's Top Level Await implementation allows for modules to be loaded in parallel. This breaks the assumption that a global __webpack_require__.$Refresh$, which contains information about the currently loading module, can be managed as a stack like data structure.

This change borrows the concept from webpack's own webpack/runtime/hot module replacement chunk that each module can receive its own copy of a "proxy" __webpack_require__. This proxy delegates all of its behavior to the global __webpack_require__ except for access to the $Refresh$ property. In practice this guarantees that __webpack_require__.$Refresh$ is isolated to the currently loading module, avoiding any chance of a race condition caused by parallel loading.

This has been found to solve the motivating issue in a 3000+ file (proprietary) Typescript/webpack build chain monorepo.

Fixes #729

Copy link

codesandbox bot commented Feb 15, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@pmmmwh
Copy link
Owner

pmmmwh commented Mar 10, 2025

Hi! Thanks for the PR. Unfortunately I have been a bit busy lately so I did not get to this - but I will try to handle it this week.

(Closed / reopened the PR to get CI running)

@pmmmwh pmmmwh added the bug Something isn't working label Mar 10, 2025
@pmmmwh pmmmwh self-requested a review March 10, 2025 10:07
@pmmmwh pmmmwh changed the title Fix/tla out of order cleanup fix: out of order cleanup with top-level await Mar 10, 2025
@pmmmwh pmmmwh closed this Mar 10, 2025
@pmmmwh pmmmwh reopened this Mar 10, 2025
@pmmmwh pmmmwh force-pushed the fix/TLA-out-of-order-cleanup branch from 4e20d82 to 5626751 Compare March 31, 2025 00:21
@pmmmwh pmmmwh force-pushed the fix/TLA-out-of-order-cleanup branch from 5626751 to e817e07 Compare March 31, 2025 00:32
@pmmmwh
Copy link
Owner

pmmmwh commented Mar 31, 2025

Thank you for fixing this!

@pmmmwh pmmmwh merged commit 92d7fd6 into pmmmwh:main Mar 31, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Webpack top level await doesn't work correctly
2 participants