fix: handle child stats without root assets#717
Conversation
|
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR fixes a crash/incorrect handling in getViewerData when bundle stats are stored in children and the “root” child compilation has no assets array, and adds a regression test for that scenario.
Changes:
- Default
bundleStats.assetsto an empty array after selecting the root child compilation. - Add a test case covering “root child has no assets, but another child contains assets/modules”.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/analyzer-get-viewer-data.js | Adds a regression test ensuring child assets are still surfaced when the root child has no assets. |
| src/analyzer.js | Ensures bundleStats.assets is initialized after switching bundleStats to the first child compilation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ) { | ||
| const { children } = bundleStats; | ||
| [bundleStats] = bundleStats.children; | ||
| bundleStats.assets ||= []; |
|
Please accept CLA and fix copilot review |
What
Initialize the selected child stats object's
assetsarray before appending assets from later child compilations.Why
When root stats contain only
children, and the first child has noassetswhile a later child does,getViewerData()currently tries to push intoundefinedand crashes before producing chart data. This is one of the missing-stats-shape cases discussed in #490.How
Added a focused regression test for that stats shape and guarded the selected child stats with an empty
assetsarray before merging later child assets.Validation
NODE_OPTIONS=--openssl-legacy-provider npx jest test/analyzer-get-viewer-data.js --runInBandfailed before the fix withCannot read properties of undefined (reading 'push')NODE_OPTIONS=--openssl-legacy-provider npx jest test/analyzer-get-viewer-data.js --runInBandnpm run buildNODE_OPTIONS=--openssl-legacy-provider npx jest test/analyzer-get-viewer-data.js test/analyzer.js --runInBand --testTimeout=60000npm run lintgit diff --checkNote: I also tried the full Jest suite with
--testTimeout=60000; the analyzer tests passed, but the run failed intest/plugin.jsafter 128 passed / 4 skipped due to a local PuppeteerafterEachbrowser cleanup timeout.