Skip to content
Merged
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
13 changes: 6 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,13 @@ upgrade-gitignore-stats:
fi

upgrade-remove-husky:
@test -d .husky\
&& rm -R .husky\
&& git add .husky\
&& git commit .husky -m"maint: @patternslib/dev upgrade - remove .husky directory in favor of git hooks."\
@test -d .husky \
&& rm -R .husky \
&& git add .husky \
&& git commit .husky -m"maint: @patternslib/dev upgrade - remove .husky directory in favor of git hooks." \
&& echo "Removed husky configuration in favor of git commit hooks." \
|| :
@# supress output, even in error case:
@git config --unset core.hooksPath || :
echo "Upgraded husky configuration"
@git config --unset core.hooksPath 2>/dev/null || :

eslint.config.js upgrade-eslint:
@test -f "eslint.config.js"\
Expand Down
2 changes: 1 addition & 1 deletion docs/adr/0003-link-sunburst-segments-to-chunks.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Link sunburst segments to the existing asset filter

Status: Proposed (2026-12-01)
Status: Superseded by 0004 (2026-12-01)

## Context

Expand Down
36 changes: 36 additions & 0 deletions docs/adr/0004-select-chunk-from-sunburst-segment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Select a matching chunk when a sunburst segment is activated

Status: Proposed (2026-12-01)

## Context

ADR 0003 filtered the chunk dropdown when a sunburst segment was activated,
but kept the current selection. The chart therefore did not change, and
users still had to pick a chunk themselves. Clearing the filter also kept
the selected chunk, so the chart and the dropdown could show a chunk the
user no longer meant to inspect.

The dropdown is a controlled React `<select>`. Setting `option.selected`
or hiding options does not update the visualizer's state.

## Decision

When a segment is activated, hide and disable nonmatching options as before
and select a matching chunk: keep the current chunk if it matches, otherwise
select the first match. Without matches, keep the current selection.

Select an option by setting the select's value and dispatching a bubbling
`change` event, so that the visualizer's React `onChange` handler updates
its state and redraws the chart.

Keep the filter while users switch between the matching chunks. Only
"Clear chunk filter" restores the full list, and it also selects
"All Chunks".

## Consequences

- Activating a segment shows the chart of a chunk containing it.
- Users can compare the matching chunks without losing the filter.
- Clearing the filter returns to the "All Modules" overview.
- The script relies on React handling a dispatched `change` event on the
select. Check this when upgrading the visualizer.
26 changes: 22 additions & 4 deletions webpack/stats-sunburst-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,24 @@
reset_filter.hidden = true;
asset_filter.after(reset_filter, filter_status);

// The dropdown is a controlled React component. Set the value and
// dispatch a change event so that React updates its state and the chart.
function select_option(option) {
if (option.selected) {
return;
}
asset_filter.value = option.value;
asset_filter.dispatchEvent(new Event("change", { bubbles: true }));
}

function clear_filter() {
for (const option of asset_options) {
option.hidden = false;
option.disabled = false;
}
filter_status.textContent = "";
reset_filter.hidden = true;
select_option(asset_filter.options[0]);
}

function show_assets(segment) {
Expand All @@ -62,13 +73,21 @@
}
}

// Keep React's option nodes and selected value in place. Disable hidden
// options so they are also skipped during keyboard navigation.
// Select a matching chunk, unless the current one already matches.
// Without matches, keep the current selection.
const selected = asset_filter.selectedOptions[0];
const target = assets.has(selected)
? selected
: asset_options.find((option) => assets.has(option)) || selected;

// Keep React's option nodes in place. Disable hidden options so they
// are also skipped during keyboard navigation.
for (const option of asset_options) {
const excluded = !option.selected && !assets.has(option);
const excluded = option !== target && !assets.has(option);
option.hidden = excluded;
option.disabled = excluded;
}
select_option(target);
const segment_name = segment.fullName || segment.name;
filter_status.textContent = assets.size
? `Showing chunks containing ${segment_name}.`
Expand All @@ -81,7 +100,6 @@
clear_filter();
asset_filter.focus();
});
asset_filter.addEventListener("change", clear_filter);

// D3 attaches the current hierarchy node to each arc and replaces the
// arcs on filter changes. Keep the keyboard controls on the new arcs.
Expand Down
2 changes: 2 additions & 0 deletions webpack/stats-sunburst.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ if (modules_by_chunk.size) {
const reduced_stats = {
assets: (stats.assets || []).map((asset) => ({
name: asset.name,
size: asset.size,
chunks: asset.chunks,
})),
chunks: chunks.map((chunk) => ({
id: chunk.id,
size: chunk.size,
modules: reduce_modules(chunk.modules ?? modules_by_chunk.get(chunk.id)),
})),
modules: reduce_modules(stats.modules),
Expand Down