r/react • • 1d ago

Project / Code Review cogni: give your next react screen a head start

say you have an orders page that loads its javascript when someone clicks “orders”. there’s often a little time between the pointer settling on the link and the click. cogni can start the import in that gap. by the time the user clicks, some or all of the work may already be done.

we built this at inttegro because starting the request is the easy part. suppose the user hovers over “orders” and then opens “products”. the orders request might have finished just fine. it still didn’t help. cogni puts a budget on speculative work and learns from what the app actually reuses. you can see both outcomes in devtools.

if you use react router or tanstack router, start with one PredictiveLink on a screen that’s slow to open. cogni uses the router’s existing cache, so you can try it on one route before deciding whether it belongs anywhere else. if you’ve built your own navigation, the plain react demo shows the whole thing with two lazy imports and useRouteIntent.

it’s MIT-licensed. here’s the repo and the react demo. i’ll be around if anyone has questions.

0 Upvotes

5 comments sorted by

4

u/Honey-Entire 1d ago

-1

u/yawboakye 1d ago

not really. we started with prefetch but didn’t get the experience we wanted because prefetch isn’t a guided loading mechanism. this is closer to cpu’s branch prediction than a link prefetch. because it learns and adjusts strategy. in fact it has an adaptive mode where it’s able to adapt to the actual browsing/navigation behavior of a user.

1

u/Honey-Entire 1d ago

Feel free to expound because you didn’t actually say anything worth saying in your response. Browser prefetch already supports building this type of UX with far less code & complexity. Moreover you don’t need react and this would be better as a vanilla JS package if it was actually worth delivering as a package.

What experience does prefetch not provide? Why does prefetching need CPU-like branch prediction? What alternatives did you consider before spending tokens to have AI generate this? Why does everything have to “learn” when the reality is a simple, non-adaptive algorithm is perfectly fine and performant?

-1

u/yawboakye 1d ago

i’m glad you’ve found a setup that works for you. this is what worked for us, and we’re happy to share with the community. on spending tokens, we have different pocket depths so while i appreciate your concern, we’re not facing the same crunch that should force us into “token accounting.” i’m grateful for my abundance. cheers 🥂

2

u/Intelligent-Main539 1d ago

Posts like this feel like just a way to get a product promoted.

+1 for the other comment.