Skip to content

Commit

Permalink
Mark previously deferred assets as dirty for symbol prop (#9369)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcompiles authored Nov 12, 2023
1 parent 7a68dc9 commit c784885
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/core/core/src/requests/AssetGraphRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ export class AssetGraphBuilder {
if (!previouslyDeferred && childNode.deferred) {
this.assetGraph.markParentsWithHasDeferred(childNodeId);
} else if (previouslyDeferred && !childNode.deferred) {
// Mark Asset and Dependency as dirty for symbol propagation as it was
// previously deferred and it's used symbols may have changed
this.changedAssetsPropagation.add(node.id);
node.usedSymbolsDownDirty = true;
this.changedAssetsPropagation.add(childNode.id);
childNode.usedSymbolsDownDirty = true;

this.assetGraph.unmarkParentsWithHasDeferred(childNodeId);
}

Expand Down
84 changes: 83 additions & 1 deletion packages/core/integration-tests/test/lazy-compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,23 @@ import {
assertBundles,
removeDistDirectory,
run,
fsFixture,
overlayFS,
} from '@parcel/test-utils';

const findBundle = (bundleGraph, nameRegex) => {
return bundleGraph.getBundles().find(b => nameRegex.test(b.name));
const result = bundleGraph.getBundles().find(b => nameRegex.test(b.name));

if (!result) {
throw new Error(
`Couldn't find bundle matching '${nameRegex}'. Available bundles are ${bundleGraph
?.getBundles()
.map(b => b.name)
.join(', ')}`,
);
}

return result;
};

const distDirIncludes = async matches => {
Expand Down Expand Up @@ -261,4 +274,73 @@ describe('lazy compile', function () {
]);
subscription.unsubscribe();
});

it('should lazy compile properly when an assets needs to be re-visited in symbol propagation', async () => {
await fsFixture(overlayFS, __dirname)`
lazy-compile-import-symbols
index.js:
import { shared, async } from './main';
export default Promise.all([shared(), async()]);
main.js:
export function shared() {
return import('./shared');
}
export function async() {
return import('./async');
}
async.js:
// Trigger more deps so a full 'propagateSymbolsUp' pass is executed
import './a';
import './b';
import './c';
import { other } from './shared';
export default other;
shared.js:
export const main = 'main';
export const other = 'other';
a.js:
sideEffectNoop();
b.js:
sideEffectNoop();
c.js:
sideEffectNoop();
`;

const b = await bundler(
path.join(__dirname, 'lazy-compile-import-symbols/index.js'),
{
shouldBuildLazily: true,
mode: 'development',
shouldContentHash: false,
inputFS: overlayFS,
},
);

await removeDistDirectory();

const subscription = await b.watch();
let result = await getNextBuild(b);
result = await result.requestBundle(
findBundle(result.bundleGraph, /^index\.js/),
);
result = await result.requestBundle(
findBundle(result.bundleGraph, /^async\./),
);

let output = await run(result.bundleGraph);
assert.deepEqual(await output.default, [
{
main: 'main',
other: 'other',
},
{
default: 'other',
},
]);
subscription.unsubscribe();
});
});

0 comments on commit c784885

Please sign in to comment.