Skip to content

Commit e46f6a0

Browse files
committed
fix: Wrap routes in fragment to avoid rerenders from router return?
1 parent f9191bd commit e46f6a0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/router.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { h, createContext, cloneElement, toChildArray } from 'preact';
1+
import { h, Fragment, createContext, cloneElement, toChildArray } from 'preact';
22
import { useContext, useMemo, useReducer, useLayoutEffect, useRef } from 'preact/hooks';
33

44
/**
@@ -178,10 +178,10 @@ export function Router(props) {
178178
const routeChanged = useMemo(() => {
179179
prev.current = cur.current;
180180

181-
cur.current = incoming;
181+
cur.current = /** @type {VNode<any>} */ (h(Fragment, { key: path }, incoming));
182182

183183
// Only mark as an update if the route component changed.
184-
const outgoing = prev.current;
184+
const outgoing = prev.current && prev.current.props.children;
185185
if (!outgoing || !incoming || incoming.type !== outgoing.type || incoming.props.component !== outgoing.props.component) {
186186
// This hack prevents Preact from diffing when we swap `cur` to `prev`:
187187
if (this.__v && this.__v.__k) this.__v.__k.reverse();

0 commit comments

Comments
 (0)