@@ -274,11 +274,14 @@ function InputRenderer({
274274 )
275275}
276276
277- function isInternalHref ( href : string ) : { pathname : string ; hash : string } | null {
277+ function isInternalHref (
278+ href : string ,
279+ origin = window . location . origin
280+ ) : { pathname : string ; hash : string } | null {
278281 if ( href . startsWith ( '#' ) ) return { pathname : '' , hash : href }
279282 try {
280- const url = new URL ( href , window . location . origin )
281- if ( url . origin === window . location . origin ) {
283+ const url = new URL ( href , origin )
284+ if ( url . origin === origin ) {
282285 return { pathname : url . pathname , hash : url . hash }
283286 }
284287 } catch {
@@ -303,12 +306,22 @@ function AnchorRenderer({ href, children }: { href?: string; children?: React.Re
303306
304307 if ( parsed . pathname === '' && parsed . hash ) {
305308 const el = document . getElementById ( parsed . hash . slice ( 1 ) )
306- el ?. scrollIntoView ( { behavior : 'smooth' } )
309+ if ( el ) {
310+ const container = el . closest ( '.overflow-auto' ) as HTMLElement | null
311+ if ( container ) {
312+ container . scrollTo ( { top : el . offsetTop - container . offsetTop , behavior : 'smooth' } )
313+ } else {
314+ el . scrollIntoView ( { behavior : 'smooth' } )
315+ }
316+ }
307317 return
308318 }
309319
320+ const destination = parsed . pathname + parsed . hash
310321 if ( navigate ) {
311- navigate ( parsed . pathname + parsed . hash )
322+ navigate ( destination )
323+ } else {
324+ window . location . assign ( destination )
312325 }
313326 } ,
314327 [ parsed , navigate ]
0 commit comments