11import React from "preact/compat" ;
22import ReactDOM from "preact/compat" ;
3- import { createLocationObject } from "./utils" ;
3+ import { createLocationObject , pushState , replaceState } from "./utils" ;
44import {
55 HistoryProps ,
66 LinkProps ,
@@ -43,7 +43,6 @@ export function History({ onHistoryChangeCallback }: HistoryProps): null {
4343 // FIXME: This code is commented out since it currently runs every time any component
4444 // is mounted due to a ReactPy core rendering bug. `FirstLoad` component is used instead.
4545 // https://github.com/reactive-python/reactpy/pull/1224
46-
4746 // React.useEffect(() => {
4847 // onHistoryChange({
4948 // pathname: window.location.pathname,
@@ -69,7 +68,7 @@ export function Link({ onClickCallback, linkClass }: LinkProps): null {
6968 const handleClick = ( event : MouseEvent ) => {
7069 event . preventDefault ( ) ;
7170 let to = ( event . target as HTMLElement ) . getAttribute ( "href" ) ;
72- window . history . pushState ( null , "" , new URL ( to , window . location . href ) ) ;
71+ pushState ( to ) ;
7372 onClickCallback ( createLocationObject ( ) ) ;
7473 } ;
7574
@@ -78,7 +77,7 @@ export function Link({ onClickCallback, linkClass }: LinkProps): null {
7877 if ( link ) {
7978 link . addEventListener ( "click" , handleClick ) ;
8079 } else {
81- console . warn ( `Link component with class name ${ link } not found.` ) ;
80+ console . warn ( `Link component with class name ${ linkClass } not found.` ) ;
8281 }
8382
8483 // Delete the event listener when the component is unmounted
@@ -102,13 +101,13 @@ export function Navigate({
102101} : NavigateProps ) : null {
103102 React . useEffect ( ( ) => {
104103 if ( replace ) {
105- window . history . replaceState ( null , "" , new URL ( to , window . location . href ) ) ;
104+ replaceState ( to ) ;
106105 } else {
107- window . history . pushState ( null , "" , new URL ( to , window . location . href ) ) ;
106+ pushState ( to ) ;
108107 }
109108 onNavigateCallback ( createLocationObject ( ) ) ;
110109 return ( ) => { } ;
111- } , [ onNavigateCallback , to , replace ] ) ;
110+ } , [ ] ) ;
112111
113112 return null ;
114113}
@@ -123,7 +122,7 @@ export function FirstLoad({ onFirstLoadCallback }: FirstLoadProps): null {
123122 React . useEffect ( ( ) => {
124123 onFirstLoadCallback ( createLocationObject ( ) ) ;
125124 return ( ) => { } ;
126- } , [ onFirstLoadCallback ] ) ;
125+ } , [ ] ) ;
127126
128127 return null ;
129128}
0 commit comments