File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
src/lib_components/components/NeonPage Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -422,9 +422,6 @@ const NeonPage = (props) => {
422422 if ( sidebarLinks . length === 5 ) {
423423 return sidebarLinks [ 3 ] . hash ;
424424 }
425- if ( sidebarLinks . length === 7 ) {
426- return sidebarLinks [ 1 ] . hash ;
427- }
428425 return '#' ;
429426 } ) ( ) ;
430427 const currentSidebarHash = initialCurrentSidebarHash ;
@@ -438,7 +435,19 @@ const NeonPage = (props) => {
438435 const headerOffset = ( headerRef . current || { } ) . offsetHeight || 0 ;
439436 const stickyOffset = belowMd ? ( sidebarRef . current || { } ) . offsetHeight || 0 : 0 ;
440437 if ( hash === '#' ) { return 0 ; }
441- const anchor = contentRef . current . querySelector ( hash ) ;
438+ let selector = null ;
439+ try {
440+ const url = new URL ( hash , window . location . origin ) ;
441+ selector = url . hash ;
442+ } catch {
443+ if ( hash . startsWith ( '#' ) ) {
444+ selector = hash ;
445+ }
446+ }
447+ if ( ! selector ) {
448+ return - 1 ;
449+ }
450+ const anchor = contentRef . current . querySelector ( selector ) ;
442451 return ! anchor ? - 1 : anchor . offsetTop + headerOffset - stickyOffset - Theme . spacing ( 5 ) ;
443452 } , [ hasSidebarLinks , sidebarLinksAsStandaloneChildren , belowMd ] ) ;
444453
You can’t perform that action at this time.
0 commit comments