Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
684fb730
Unverified
Commit
684fb730
authored
Dec 18, 2025
by
Will Binns-Smith
Committed by
GitHub
Dec 18, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bundle analyzer: prevent flashes and stuck empty canvases on resize (#87289)
parent
1c09f449
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
28 deletions
+38
-28
treemap-visualizer.tsx
apps/bundle-analyzer/components/treemap-visualizer.tsx
+38
-28
No files found.
apps/bundle-analyzer/components/treemap-visualizer.tsx
View file @
684fb730
...
...
@@ -2,7 +2,7 @@
import
{
darken
,
lighten
,
readableColor
}
from
'polished'
import
type
React
from
'react'
import
{
useEffect
,
useMemo
,
useRef
,
useState
}
from
'react'
import
{
useEffect
,
use
LayoutEffect
,
use
Memo
,
useRef
,
useState
}
from
'react'
import
type
{
AnalyzeData
}
from
'@/lib/analyze-data'
import
{
computeTreemapLayoutFromAnalyze
,
...
...
@@ -718,13 +718,16 @@ export function TreemapVisualizer({
const
[
hoveredNode
,
setHoveredNode
]
=
useState
<
LayoutNode
|
null
>
(
null
)
const
[
shouldDimOthers
,
setShouldDimOthers
]
=
useState
(
false
)
const
hoverTimeoutRef
=
useRef
<
NodeJS
.
Timeout
|
null
>
(
null
)
const
[
cssDimensions
,
setCssDimensions
]
=
useState
({
width
:
1200
,
height
:
800
,
})
const
[
canvasDimensions
,
setCanvasDimensions
]
=
useState
({
width
:
1200
,
height
:
800
,
const
[
dimensions
,
setDimensions
]
=
useState
<
{
cssWidth
:
number
cssHeight
:
number
canvasWidth
:
number
canvasHeight
:
number
}
>
({
cssWidth
:
1200
,
cssHeight
:
800
,
canvasWidth
:
1200
,
canvasHeight
:
800
,
})
const
[,
_setTheme
]
=
useState
<
'light'
|
'dark'
>
(
'light'
)
...
...
@@ -785,15 +788,22 @@ export function TreemapVisualizer({
if
(
!
container
)
return
const
updateSize
=
()
=>
{
const
rect
=
container
.
getBoundingClientRect
()
const
dpr
=
window
.
devicePixelRatio
||
1
setCssDimensions
({
width
:
Math
.
floor
(
rect
.
width
),
height
:
Math
.
floor
(
rect
.
height
),
})
setCanvasDimensions
({
width
:
Math
.
floor
(
rect
.
width
*
dpr
),
height
:
Math
.
floor
(
rect
.
height
*
dpr
),
setDimensions
((
dimensions
)
=>
{
const
rect
=
container
.
getBoundingClientRect
()
if
(
dimensions
.
cssWidth
===
Math
.
floor
(
rect
.
width
)
&&
dimensions
.
cssHeight
===
Math
.
floor
(
rect
.
height
)
)
{
return
dimensions
}
return
{
cssWidth
:
Math
.
floor
(
rect
.
width
),
cssHeight
:
Math
.
floor
(
rect
.
height
),
canvasWidth
:
Math
.
floor
(
rect
.
width
*
dpr
),
canvasHeight
:
Math
.
floor
(
rect
.
height
*
dpr
),
}
})
}
...
...
@@ -813,8 +823,8 @@ export function TreemapVisualizer({
{
x
:
0
,
y
:
12
*
focusedAncestorChain
.
length
,
width
:
cssDimensions
.
w
idth
,
height
:
cssDimensions
.
h
eight
,
width
:
dimensions
.
cssW
idth
,
height
:
dimensions
.
cssH
eight
,
},
filterSource
,
sizeMode
...
...
@@ -826,8 +836,8 @@ export function TreemapVisualizer({
focusedLayout
,
focusedAncestorChain
,
analyzeData
,
cssDimensions
.
w
idth
,
cssDimensions
.
h
eight
,
dimensions
.
cssW
idth
,
dimensions
.
cssH
eight
,
12
)
}
...
...
@@ -837,13 +847,13 @@ export function TreemapVisualizer({
analyzeData
,
focusedSourceIndex
,
focusedAncestorChain
,
cssDimensions
.
w
idth
,
cssDimensions
.
h
eight
,
dimensions
.
cssW
idth
,
dimensions
.
cssH
eight
,
filterSource
,
sizeMode
,
])
useEffect
(()
=>
{
use
Layout
Effect
(()
=>
{
const
canvas
=
canvasRef
.
current
if
(
!
canvas
)
return
...
...
@@ -854,7 +864,7 @@ export function TreemapVisualizer({
ctx
.
setTransform
(
1
,
0
,
0
,
1
,
0
,
0
)
ctx
.
scale
(
dpr
,
dpr
)
ctx
.
clearRect
(
0
,
0
,
cssDimensions
.
width
,
cssDimensions
.
h
eight
)
ctx
.
clearRect
(
0
,
0
,
dimensions
.
cssWidth
,
dimensions
.
cssH
eight
)
drawTreemap
(
ctx
,
...
...
@@ -871,8 +881,8 @@ export function TreemapVisualizer({
layout
,
hoveredAncestorChain
,
selectedAncestorChain
,
cssDimensions
.
w
idth
,
cssDimensions
.
h
eight
,
dimensions
.
cssW
idth
,
dimensions
.
cssH
eight
,
isMouseInTreemap
,
focusedAncestorChain
,
searchQuery
,
...
...
@@ -1005,8 +1015,8 @@ export function TreemapVisualizer({
>
<
canvas
ref=
{
canvasRef
}
width=
{
canvasDimensions
.
w
idth
}
height=
{
canvasDimensions
.
h
eight
}
width=
{
dimensions
.
canvasW
idth
}
height=
{
dimensions
.
canvasH
eight
}
onMouseMove=
{
handleMouseMove
}
onMouseLeave=
{
handleMouseLeave
}
onClick=
{
handleClick
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment