Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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();
await page.goto(
url.pathToFileURL(path.resolve(__dirname, "./output/report.html")),
);

const { chunkLabel, initialTreemapChunks } = await page.evaluate(() => {
const modulesTreemap = document
.querySelector("#app")
.__k.__k.find(
(vnode) => vnode.__c && vnode.__c.handleSelectedChunksChange,
).__c;

return {
chunkLabel: globalThis.chartData[0].label,
initialTreemapChunks: modulesTreemap.treemap.props.data.map(
(chunk) => chunk.label,
),
};
});

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.evaluate(
() =>
new Promise((resolve) => {
setTimeout(resolve);
}),
);

const updatedTreemapChunks = await page.evaluate(() => {
const modulesTreemap = document
.querySelector("#app")
.__k.__k.find(
(vnode) => vnode.__c && vnode.__c.handleSelectedChunksChange,
).__c;

return modulesTreemap.treemap.props.data.map((chunk) => chunk.label);
});
Comment thread
christiango marked this conversation as resolved.
Outdated

expect(checkboxChecked).toBe(false);
expect(initialTreemapChunks).toContain(chunkLabel);
expect(updatedTreemapChunks).not.toContain(chunkLabel);
});
Comment thread
christiango marked this conversation as resolved.
Outdated

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