Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-chunk-selection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"webpack-bundle-analyzer": patch
---

Fix the treemap not reflecting chunk checkbox selections.
2 changes: 1 addition & 1 deletion client/components/ModulesTreemap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class ModulesTreemap extends Component {
};

handleSelectedChunksChange = (selectedChunks) => {
store.setSelectedSize(selectedChunks);
store.setSelectedChunks(selectedChunks);
};

handleMouseLeaveTreemap = () => {
Expand Down
53 changes: 53 additions & 0 deletions test/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,59 @@ describe("Analyzer", () => {
});
});

it("should update the treemap when a chunk is deselected", async () => {
generateReportFrom("with-worker-loader-dynamic-import/stats.json");
const page = await browser.newPage();
try {
await page.goto(
url.pathToFileURL(path.resolve(__dirname, "./output/report.html")),
);

const chunkLabel = await page.evaluate(
() => globalThis.chartData[0].label,
);

await page.type('input[placeholder="Enter regexp"]', ".");
await page.keyboard.press("Enter");
await page.waitForFunction(
(label) =>
[
...document.querySelectorAll('[class*="foundModulesChunkName"]'),
].some((node) => node.textContent.trim() === label),
{},
chunkLabel,
);

const checkboxChecked = await page.evaluate((label) => {
const checkboxLabel = [...document.querySelectorAll("label")].find(
(node) => node.textContent.trim().startsWith(`${label} (`),
);
const checkbox = checkboxLabel.querySelector('input[type="checkbox"]');
checkbox.click();
return checkbox.checked;
}, chunkLabel);

await page.waitForFunction(
(label) =>
![
...document.querySelectorAll('[class*="foundModulesChunkName"]'),
].some((node) => node.textContent.trim() === label),
{},
chunkLabel,
);

const visibleChunkLabels = await page.$$eval(
'[class*="foundModulesChunkName"]',
(nodes) => nodes.map((node) => node.textContent.trim()),
);

expect(checkboxChecked).toBe(false);
expect(visibleChunkLabels).not.toContain(chunkLabel);
} finally {
await page.close();
}
});

it("should support stats files with modules inside `chunks` array", async () => {
generateReportFrom("with-modules-in-chunks/stats.json");
const chartData = await getChartData();
Expand Down