Fix RequireJS min resolver for unbundled contexts - #41072
Conversation
ACP2E-4058 made the mixins unbundled RequireJS context reuse the default context nameToUrl resolver so minified URLs are generated correctly. The default resolver also contains bundle resolution, so bundled modules can resolve to bundle paths during mixin lookup instead of their original module IDs. Mixins configured by module name are then skipped. Move the minification behavior to the generated min resolver by decorating each RequireJS context's own nameToUrl implementation, including contexts created after the resolver is loaded. This preserves minified URL rewriting without leaking the default context bundle map into the mixins unbundled context. Remove the direct nameToUrl assignment from mixins.js and keep bundles out of the unbundled context when forwarding later require.config calls. Update unit and Jasmine expectations to cover the intended context separation. Fixes magento#41071
|
Hi @GrassH. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
|
@magento run all tests |
Add explicit public visibility to RequireJS config constants to satisfy the PHP coding standard. Document the deprecated DIR_NAME constant with an alternative reference, and remove the unreachable empty() branch in getMinResolverCode() reported by PHPStan.
|
@magento run Static Tests |
|
I reviewed the failed test reports for Functional CE, Functional B2B, Functional EE, and WebApi. The failures do not appear to be related to this PR. This PR only changes RequireJS config/min resolver behavior and the The only related failure was in Statics:
These static issues have been fixed in commit 895783f. Other failures are unrelated:
Given the failure locations and messages, these should be treated as unrelated flaky/environment/test-data failures or handled |
|
@magento run all tests |
Split the long Jasmine test description so the RequireJS mixins test satisfies the ESLint max-len rule without changing test behavior.
|
@magento run all tests |
Description (*)
ACP2E-4058 made the
mage/requirejs/mixins.jsunbundled RequireJS context reuse the default contextnameToUrlresolver so minified URLs are generated correctly.That fixed minified URL generation for the unbundled context, but it also copied default context bundle resolution into that
context. As a result, bundled modules can resolve to bundle paths during mixin lookup instead of their original module IDs. For example, a module configured as:
'Magento_Checkout/js/view/billing-address'can resolve to:
'bundles/checkout'Mixin configuration is keyed by the original module name, so
mixins.getMixins('bundles/checkout')returns no mixins even thoughmixins.getMixins('Magento_Checkout/js/view/billing-address')would return the configured mixins.This pull request moves the minification behavior to the generated min resolver instead of sharing the default context resolver with the unbundled mixins context.
The generated min resolver now decorates each RequireJS context's own
nameToUrlimplementation, including contexts created after the resolver is loaded throughrequire.s.newContext. This preserves minified URL rewriting while keeping each context's own resolution behavior.The change also removes the direct
nameToUrlassignment frommixins.jsand prevents bundles config from being forwarded into the unbundled mixins context during laterrequire.config()calls.This preserves the intended separation:
Related Pull Requests
N/A
Fixed Issues (if relevant)
Manual testing scenarios (*)
Expected result:
Confirm checkout or another page using bundled RequireJS mixins renders without missing mixin-provided component properties.
Questions or comments
This pull request intentionally fixes the minification resolver layer rather than adding a fallback in mixins.js.
The previous approach made the unbundled mixins context reuse the default context resolver. That solved minified URL
generation, but it also leaked bundle resolution into a context that is specifically intended to resolve original module paths
for mixin lookup.
Contribution checklist (*)