Skip to content

Commit d718c8e

Browse files
committed
avoid loading on every render
1 parent cf5cecc commit d718c8e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

router.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export function Router(props) {
9494
const { url, query, wasPush, path } = useLocation();
9595
const { rest = path, params = {} } = useContext(RouteContext);
9696

97+
const isLoading = useRef(false);
9798
// Monotonic counter used to check if an un-suspending route is still the current route:
9899
const count = useRef(0);
99100
// The current route:
@@ -140,6 +141,7 @@ export function Router(props) {
140141

141142
// Fire an event saying we're waiting for the route:
142143
if (props.onLoadStart) props.onLoadStart(url);
144+
isLoading.current = true;
143145

144146
// Re-render on unsuspend:
145147
let c = count.current;
@@ -176,7 +178,8 @@ export function Router(props) {
176178

177179
// The route is loaded and rendered.
178180
if (wasPush) scrollTo(0, 0);
179-
if (props.onLoadEnd) props.onLoadEnd(url);
181+
if (props.onLoadEnd && isLoading.current) props.onLoadEnd(url);
182+
isLoading.current = false;
180183
});
181184

182185
// Note: curChildren MUST render first in order to set didSuspend & prev.

0 commit comments

Comments
 (0)