Wrap assets recursively when any incoming dependency is wrapped #6572
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.
Fixes #6519.
This ensures that we wrap all assets recursively when any incoming dependency is wrapped. Previously, we'd only wrap the asset the dependency pointed to, not necessarily its dependencies as well. In the test case, a has a circular dependency on b -> a. c also depends on a, but forces a to be wrapped by requiring it inside a function. However, b was left unwrapped, resulting in a
parcelRequire
call toa
that ran before a's other dependencies which are still unwrapped –💥. Basically, if an asset is wrapped, all of its children also have to be wrapped, but this wasn't true in some cases due to DFS stopping when it hits a node its seen already. Now we check all incoming dependencies for each asset rather than relying on the context when hitting dependency nodes.