Skip to content

Commit a06b641

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

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/router.js

+3-3
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
/**
@@ -149,10 +149,10 @@ export function Router(props) {
149149
const routeChanged = useMemo(() => {
150150
prev.current = cur.current;
151151

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

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

0 commit comments

Comments
 (0)