Skip to content

Commit 48798a8

Browse files
authored
fix: update treemap when chunk selection changes (#722)
* fix: update treemap chunk selection * test: make chunk selection test deterministic * test: avoid Preact internals in chunk selection test * test: verify chunk filtering through rendered results
1 parent 5ec0e7c commit 48798a8

3 files changed

Lines changed: 59 additions & 1 deletion

File tree

‎.changeset/fix-chunk-selection.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack-bundle-analyzer": patch
3+
---
4+
5+
Fix the treemap not reflecting chunk checkbox selections.

‎client/components/ModulesTreemap.jsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class ModulesTreemap extends Component {
331331
};
332332

333333
handleSelectedChunksChange = (selectedChunks) => {
334-
store.setSelectedSize(selectedChunks);
334+
store.setSelectedChunks(selectedChunks);
335335
};
336336

337337
handleMouseLeaveTreemap = () => {

‎test/analyzer.js‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,59 @@ describe("Analyzer", () => {
125125
});
126126
});
127127

128+
it("should update the treemap when a chunk is deselected", async () => {
129+
generateReportFrom("with-worker-loader-dynamic-import/stats.json");
130+
const page = await browser.newPage();
131+
try {
132+
await page.goto(
133+
url.pathToFileURL(path.resolve(__dirname, "./output/report.html")),
134+
);
135+
136+
const chunkLabel = await page.evaluate(
137+
() => globalThis.chartData[0].label,
138+
);
139+
140+
await page.type('input[placeholder="Enter regexp"]', ".");
141+
await page.keyboard.press("Enter");
142+
await page.waitForFunction(
143+
(label) =>
144+
[
145+
...document.querySelectorAll('[class*="foundModulesChunkName"]'),
146+
].some((node) => node.textContent.trim() === label),
147+
{},
148+
chunkLabel,
149+
);
150+
151+
const checkboxChecked = await page.evaluate((label) => {
152+
const checkboxLabel = [...document.querySelectorAll("label")].find(
153+
(node) => node.textContent.trim().startsWith(`${label} (`),
154+
);
155+
const checkbox = checkboxLabel.querySelector('input[type="checkbox"]');
156+
checkbox.click();
157+
return checkbox.checked;
158+
}, chunkLabel);
159+
160+
await page.waitForFunction(
161+
(label) =>
162+
![
163+
...document.querySelectorAll('[class*="foundModulesChunkName"]'),
164+
].some((node) => node.textContent.trim() === label),
165+
{},
166+
chunkLabel,
167+
);
168+
169+
const visibleChunkLabels = await page.$$eval(
170+
'[class*="foundModulesChunkName"]',
171+
(nodes) => nodes.map((node) => node.textContent.trim()),
172+
);
173+
174+
expect(checkboxChecked).toBe(false);
175+
expect(visibleChunkLabels).not.toContain(chunkLabel);
176+
} finally {
177+
await page.close();
178+
}
179+
});
180+
128181
it("should support stats files with modules inside `chunks` array", async () => {
129182
generateReportFrom("with-modules-in-chunks/stats.json");
130183
const chartData = await getChartData();

0 commit comments

Comments
 (0)