diff --git a/packages/bundlers/experimental/src/ExperimentalBundler.js b/packages/bundlers/experimental/src/ExperimentalBundler.js index 42698fa87d1..805d7456cd1 100644 --- a/packages/bundlers/experimental/src/ExperimentalBundler.js +++ b/packages/bundlers/experimental/src/ExperimentalBundler.js @@ -404,6 +404,15 @@ function createIdealGraph( } else { bundle = nullthrows(bundleGraph.getNode(bundleId)); invariant(bundle !== 'root'); + + if ( + // If this dependency requests isolated, but the bundle is not, + // make the bundle isolated for all uses. + dependency.bundleBehavior === 'isolated' && + bundle.bundleBehavior == null + ) { + bundle.bundleBehavior = dependency.bundleBehavior; + } } dependencyBundleGraph.addEdge( diff --git a/packages/core/integration-tests/test/javascript.js b/packages/core/integration-tests/test/javascript.js index 8a77a27394c..1b0e229bd9d 100644 --- a/packages/core/integration-tests/test/javascript.js +++ b/packages/core/integration-tests/test/javascript.js @@ -5699,27 +5699,47 @@ describe('javascript', function () { ), ); - assertBundles(b, [ - { - type: 'js', - assets: [ - 'dynamic-url.js', - 'esmodule-helpers.js', - 'bundle-url.js', - 'cacheLoader.js', - 'js-loader.js', - ], - }, - { - type: 'js', - assets: ['other.js'], - }, - { - type: 'js', - assets: ['other.js', 'esmodule-helpers.js'], - }, - ]); - + // Change in behavior: ExperimentalBundler now produces a single bundle + // of the lowest common denominator of bundleBehavior + if (process.env.PARCEL_TEST_EXPERIMENTAL_BUNDLER) { + assertBundles(b, [ + { + type: 'js', + assets: [ + 'dynamic-url.js', + 'esmodule-helpers.js', + 'bundle-url.js', + 'cacheLoader.js', + 'js-loader.js', + ], + }, + { + type: 'js', + assets: ['other.js', 'esmodule-helpers.js'], + }, + ]); + } else { + assertBundles(b, [ + { + type: 'js', + assets: [ + 'dynamic-url.js', + 'esmodule-helpers.js', + 'bundle-url.js', + 'cacheLoader.js', + 'js-loader.js', + ], + }, + { + type: 'js', + assets: ['other.js'], + }, + { + type: 'js', + assets: ['other.js', 'esmodule-helpers.js'], + }, + ]); + } let res = await run(b); assert.equal(typeof res.lazy, 'object'); assert.equal(typeof (await res.lazy), 'function'); @@ -5744,20 +5764,35 @@ describe('javascript', function () { }, ); - assertBundles(b, [ - { - type: 'js', - assets: ['dynamic-url.js'], - }, - { - type: 'js', - assets: ['other.js'], - }, - { - type: 'js', - assets: ['other.js'], - }, - ]); + if (process.env.PARCEL_TEST_EXPERIMENTAL_BUNDLER) { + // Change in behavior: ExperimentalBundler now produces a single bundle + // of the lowest common denominator of bundleBehavior + assertBundles(b, [ + { + type: 'js', + assets: ['dynamic-url.js'], + }, + { + type: 'js', + assets: ['other.js'], + }, + ]); + } else { + assertBundles(b, [ + { + type: 'js', + assets: ['dynamic-url.js'], + }, + { + type: 'js', + assets: ['other.js'], + }, + { + type: 'js', + assets: ['other.js'], + }, + ]); + } let res = await run(b); assert.equal(typeof res.lazy, 'object');