Skip to content

Commit cd2e5f2

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

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
/**
@@ -169,10 +169,10 @@ export function Router(props) {
169169
const routeChanged = useMemo(() => {
170170
prev.current = cur.current;
171171

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

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

0 commit comments

Comments
 (0)