Skip to content

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

Merged
pmmmwh merged 2 commits into
pmmmwh:mainfrom
erm410:fix/TLA-out-of-order-cleanup
Mar 31, 2025
Merged

pmmmwh merged 2 commits into
pmmmwh:mainfrom
erm410:fix/TLA-out-of-order-cleanup

Conversation

@erm410

@erm410 erm410 commented Feb 15, 2025 •

Copy link
Copy Markdown
Contributor

#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

@codesandbox

codesandbox Bot commented Feb 15, 2025

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web Editor • VS Code • Insiders

Open Preview

@pmmmwh

pmmmwh commented Mar 10, 2025 •

Copy link
Copy Markdown
Owner

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

pmmmwh commented Mar 31, 2025

Copy link
Copy Markdown
Owner

Thank you for fixing this!

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