Support for React Activity component #82958
-
Is there any plan, to implement the React Activity component (https://react.dev/reference/react/Activity) in the app router? Can it bring any benefit during navigation? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey 👋 So right now, Next.js (even in v15) doesn’t have direct support for But you can still use it manually. Here’s a small example: 'use client';
import { useRouter } from 'next/navigation';
import { useActivity } from 'react';
export default function PageWithActivity() {
const router = useRouter();
const activity = useActivity();
React.useEffect(() => {
if (!activity.active) {
// e.g. prefetch next route if user is idle
router.prefetch('/next');
}
}, [activity.active]);
return <div>{activity.active ? 'Active' : 'Idle'}</div>;
} |
Beta Was this translation helpful? Give feedback.
-
Hi yeah this is in the works, but I guess, it has slightly lower prio over other work, and because the feature is still unstable AFAIK. If you grep around the public repo you'll find:
If you follow around there you'll see that this experimental config I should add, that, using that flag, likely opts you into |
Beta Was this translation helpful? Give feedback.
Hi yeah this is in the works, but I guess, it has slightly lower prio over other work, and because the feature is still unstable AFAIK. If you grep around the public repo you'll find:
next.js/packages/next/src/client/components/layout-router.tsx
Lines 45 to 47 in 94f422e
If you follow around there you'll see that this experimental config
routerBFCache
makes use of the Activity API to "keep previously shown other routes mounted" so that navigating back to them is immediate. This is all experimental still of course, but you can see in the…