-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
run
/ wait
can get stuck when using Next.js with App Router
#136
Comments
Hey, Would you mind to share your workaround code? With App Router and Vercel getting even more traction, this definatly should be addressed! Thanks! |
@mirko314 Thanks for sharing. That's a helpful data point. Here's what I remember the code to be. Please give this a try and let me know if that works for you: replicate = new Replicate({/*...*/})
replicate.fetch = (url, options) => {
return fetch(url, { ...options, cache: "no-store" });
}; |
Thanks @mattt, that worked well! |
@mattt @mirko314 I'm trying to use it within a replicate create/wait structure (which is equivalent to run/wait) That would be fantastic :-) I agree this should be addressed. We won't be the only ones trying to use replicate on the new next.js app router. Thanks! |
Just ran into the same issue and this #136 (comment) fixed it for me too. Thanks for the post @mattt, probably saved me hours of troubleshooting 🙌 |
@mattt Would it be possible to update the documentation with a more detailed explanation on how to use replicate-javascript on next.js recent versions? 😃 |
Rather than changing the Replicate import Replicate from 'replicate';
import { unstable_noStore as noStore } from 'next/cache';
let replicate = new Replicate(...);
export default async function Component() {
noStore();
let prediction = await replicate.predictions.create(...)
...
} API: https://nextjs.org/docs/app/api-reference/functions/unstable_noStore |
I've opened a couple PRs to help prevent further confusion about this: |
This Great, I was stuck with this issue for a day, and after reading this issue, it was finally fixed |
At yesterday's hackathon, a participant shared that predictions created and polled for completion using
run
would hang indefinitely, despite the Replicate dashboard showing that prediction as finishing minutes earlier.After debugging by adding a
console.log
statement in theprogress
callback function, we determined that this behavior was caused by the extensions tofetch
made by Next.js when using App Router 1. From "Data Fetching, Caching, and Revalidating" in the Next.js docs:Because the initial
GET /v1/predictions/{id}
response was cached, subsequent requests polling for status returned the same response, which had the initial"starting"
status.Our workaround involved setting
replicate.fetch
to a wrapped function that specified acache: no-store
fetch option. But it's unclear whether there's a better way to get the desired behavior.We should either document or add a workaround to make this work correctly in Next.js.
Footnotes
fetch
when using Pages Router, like in the "Build a website with Next.js" sample project, works as expected. ↩The text was updated successfully, but these errors were encountered: