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 @@
...
@@ -2,7 +2,7 @@
import
{
darken
,
lighten
,
readableColor
}
from
'polished'
import
{
darken
,
lighten
,
readableColor
}
from
'polished'
import
type
React
from
'react'
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
type
{
AnalyzeData
}
from
'@/lib/analyze-data'
import
{
import
{
computeTreemapLayoutFromAnalyze
,
computeTreemapLayoutFromAnalyze
,
...
@@ -718,13 +718,16 @@ export function TreemapVisualizer({
...
@@ -718,13 +718,16 @@ export function TreemapVisualizer({
const
[
hoveredNode
,
setHoveredNode
]
=
useState
<
LayoutNode
|
null
>
(
null
)
const
[
hoveredNode
,
setHoveredNode
]
=
useState
<
LayoutNode
|
null
>
(
null
)
const
[
shouldDimOthers
,
setShouldDimOthers
]
=
useState
(
false
)
const
[
shouldDimOthers
,
setShouldDimOthers
]
=
useState
(
false
)
const
hoverTimeoutRef
=
useRef
<
NodeJS
.
Timeout
|
null
>
(
null
)
const
hoverTimeoutRef
=
useRef
<
NodeJS
.
Timeout
|
null
>
(
null
)
const
[
cssDimensions
,
setCssDimensions
]
=
useState
({
const
[
dimensions
,
setDimensions
]
=
useState
<
{
width
:
1200
,
cssWidth
:
number
height
:
800
,
cssHeight
:
number
})
canvasWidth
:
number
const
[
canvasDimensions
,
setCanvasDimensions
]
=
useState
({
canvasHeight
:
number
width
:
1200
,
}
>
({
height
:
800
,
cssWidth
:
1200
,
cssHeight
:
800
,
canvasWidth
:
1200
,
canvasHeight
:
800
,
})
})
const
[,
_setTheme
]
=
useState
<
'light'
|
'dark'
>
(
'light'
)
const
[,
_setTheme
]
=
useState
<
'light'
|
'dark'
>
(
'light'
)
...
@@ -785,15 +788,22 @@ export function TreemapVisualizer({
...
@@ -785,15 +788,22 @@ export function TreemapVisualizer({
if
(
!
container
)
return
if
(
!
container
)
return
const
updateSize
=
()
=>
{
const
updateSize
=
()
=>
{
const
rect
=
container
.
getBoundingClientRect
()
const
dpr
=
window
.
devicePixelRatio
||
1
const
dpr
=
window
.
devicePixelRatio
||
1
setCssDimensions
({
setDimensions
((
dimensions
)
=>
{
width
:
Math
.
floor
(
rect
.
width
),
const
rect
=
container
.
getBoundingClientRect
()
height
:
Math
.
floor
(
rect
.
height
),
if
(
})
dimensions
.
cssWidth
===
Math
.
floor
(
rect
.
width
)
&&
setCanvasDimensions
({
dimensions
.
cssHeight
===
Math
.
floor
(
rect
.
height
)
width
:
Math
.
floor
(
rect
.
width
*
dpr
),
)
{
height
:
Math
.
floor
(
rect
.
height
*
dpr
),
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({
...
@@ -813,8 +823,8 @@ export function TreemapVisualizer({
{
{
x
:
0
,
x
:
0
,
y
:
12
*
focusedAncestorChain
.
length
,
y
:
12
*
focusedAncestorChain
.
length
,
width
:
cssDimensions
.
w
idth
,
width
:
dimensions
.
cssW
idth
,
height
:
cssDimensions
.
h
eight
,
height
:
dimensions
.
cssH
eight
,
},
},
filterSource
,
filterSource
,
sizeMode
sizeMode
...
@@ -826,8 +836,8 @@ export function TreemapVisualizer({
...
@@ -826,8 +836,8 @@ export function TreemapVisualizer({
focusedLayout
,
focusedLayout
,
focusedAncestorChain
,
focusedAncestorChain
,
analyzeData
,
analyzeData
,
cssDimensions
.
w
idth
,
dimensions
.
cssW
idth
,
cssDimensions
.
h
eight
,
dimensions
.
cssH
eight
,
12
12
)
)
}
}
...
@@ -837,13 +847,13 @@ export function TreemapVisualizer({
...
@@ -837,13 +847,13 @@ export function TreemapVisualizer({
analyzeData
,
analyzeData
,
focusedSourceIndex
,
focusedSourceIndex
,
focusedAncestorChain
,
focusedAncestorChain
,
cssDimensions
.
w
idth
,
dimensions
.
cssW
idth
,
cssDimensions
.
h
eight
,
dimensions
.
cssH
eight
,
filterSource
,
filterSource
,
sizeMode
,
sizeMode
,
])
])
useEffect
(()
=>
{
use
Layout
Effect
(()
=>
{
const
canvas
=
canvasRef
.
current
const
canvas
=
canvasRef
.
current
if
(
!
canvas
)
return
if
(
!
canvas
)
return
...
@@ -854,7 +864,7 @@ export function TreemapVisualizer({
...
@@ -854,7 +864,7 @@ export function TreemapVisualizer({
ctx
.
setTransform
(
1
,
0
,
0
,
1
,
0
,
0
)
ctx
.
setTransform
(
1
,
0
,
0
,
1
,
0
,
0
)
ctx
.
scale
(
dpr
,
dpr
)
ctx
.
scale
(
dpr
,
dpr
)
ctx
.
clearRect
(
0
,
0
,
cssDimensions
.
width
,
cssDimensions
.
h
eight
)
ctx
.
clearRect
(
0
,
0
,
dimensions
.
cssWidth
,
dimensions
.
cssH
eight
)
drawTreemap
(
drawTreemap
(
ctx
,
ctx
,
...
@@ -871,8 +881,8 @@ export function TreemapVisualizer({
...
@@ -871,8 +881,8 @@ export function TreemapVisualizer({
layout
,
layout
,
hoveredAncestorChain
,
hoveredAncestorChain
,
selectedAncestorChain
,
selectedAncestorChain
,
cssDimensions
.
w
idth
,
dimensions
.
cssW
idth
,
cssDimensions
.
h
eight
,
dimensions
.
cssH
eight
,
isMouseInTreemap
,
isMouseInTreemap
,
focusedAncestorChain
,
focusedAncestorChain
,
searchQuery
,
searchQuery
,
...
@@ -1005,8 +1015,8 @@ export function TreemapVisualizer({
...
@@ -1005,8 +1015,8 @@ export function TreemapVisualizer({
>
>
<
canvas
<
canvas
ref=
{
canvasRef
}
ref=
{
canvasRef
}
width=
{
canvasDimensions
.
w
idth
}
width=
{
dimensions
.
canvasW
idth
}
height=
{
canvasDimensions
.
h
eight
}
height=
{
dimensions
.
canvasH
eight
}
onMouseMove=
{
handleMouseMove
}
onMouseMove=
{
handleMouseMove
}
onMouseLeave=
{
handleMouseLeave
}
onMouseLeave=
{
handleMouseLeave
}
onClick=
{
handleClick
}
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