@@ -112,6 +112,26 @@ async function buildHierarchyToggle() {
112112 . stream ( )
113113 . pipeThrough ( new DecompressionStream ( "gzip" ) ) ;
114114
115+ const baseReflId = + container . dataset . refl ! ;
116+ const hierarchy : JsonHierarchy = await new Response ( json ) . json ( ) ;
117+
118+ const collapsedHierarchy = container . querySelector ( "ul" ) ! ;
119+ const expandedHierarchy = document . createElement ( "ul" ) ;
120+ expandedHierarchy . classList . add ( "tsd-hierarchy" ) ;
121+ buildExpandedHierarchy ( expandedHierarchy , hierarchy , baseReflId ) ;
122+
123+ // No point in showing the expand button if it will be the same content.
124+ // It won't be the exact same innerHTML due to links being generated less
125+ // intelligently here than in the theme (though they still go to the same place)
126+ // but if there are the same number of elements in the hierarchy, there's
127+ // no point.
128+ if (
129+ collapsedHierarchy . querySelectorAll ( "li" ) . length ==
130+ expandedHierarchy . querySelectorAll ( "li" ) . length
131+ ) {
132+ return ;
133+ }
134+
115135 const expandCollapseButton = document . createElement ( "span" ) ;
116136 expandCollapseButton . classList . add ( "tsd-hierarchy-toggle" ) ;
117137 expandCollapseButton . textContent = window . translations . hierarchy_expand ;
@@ -141,14 +161,6 @@ async function buildHierarchyToggle() {
141161 window . translations . hierarchy_expand ;
142162 }
143163 } ) ;
144-
145- const baseReflId = + container . dataset . refl ! ;
146- const hierarchy : JsonHierarchy = await new Response ( json ) . json ( ) ;
147-
148- const collapsedHierarchy = container . querySelector ( "ul" ) ! ;
149- const expandedHierarchy = document . createElement ( "ul" ) ;
150- expandedHierarchy . classList . add ( "tsd-hierarchy" ) ;
151- buildExpandedHierarchy ( expandedHierarchy , hierarchy , baseReflId ) ;
152164}
153165
154166function buildExpandedHierarchy (
@@ -177,7 +189,7 @@ function followHierarchy(
177189
178190 const item = hierarchy . reflections [ id ] ;
179191 const container = document . createElement ( "li" ) ;
180- container . classList . add ( "tsd-hierarchy" ) ;
192+ container . classList . add ( "tsd-hierarchy-item " ) ;
181193
182194 if ( id === targetId ) {
183195 const text = container . appendChild ( document . createElement ( "span" ) ) ;
0 commit comments