From de04c42b2acfe7209cc48d0e0ebb0ceb8d65404f Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Thu, 23 May 2024 09:35:50 -0700 Subject: [PATCH 1/3] merge two typescript headings into one --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 270c6d2..6c27ef3 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,8 @@ export async function POST(request) { ## TypeScript +The `Replicate` constructor and all `replicate.*` methods are fully typed. + Currently in order to support the module format used by `replicate` you'll need to set `esModuleInterop` to `true` in your tsconfig.json. ## API @@ -1020,10 +1022,6 @@ The `replicate.request()` method is used by the other methods to interact with the Replicate API. You can call this method directly to make other requests to the API. -## TypeScript - -The `Replicate` constructor and all `replicate.*` methods are fully typed. - ## Vendored Dependencies We have a few dependencies that have been bundled into the vendor directory rather than adding external npm dependencies. From 1e814afd4b48b515ec910c8397dbbe174805451c Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Thu, 23 May 2024 09:37:17 -0700 Subject: [PATCH 2/3] move note about vendored deps to CONTRIBUTING docs --- CONTRIBUTING.md | 23 +++++++++++++++++++++++ README.md | 25 +------------------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ab1d859..0b5e894 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,3 +32,26 @@ This will: - Push the commit and tag to GitHub - Publish the package to npm - Create a GitHub release + +## Vendored Dependencies + +We have a few dependencies that have been bundled into the vendor directory rather than adding external npm dependencies. + +These have been generated using bundlejs.com and copied into the appropriate directory along with the license and repository information. + +* [eventsource-parser/stream](https://bundlejs.com/?bundle&q=eventsource-parser%40latest%2Fstream&config=%7B%22esbuild%22%3A%7B%22format%22%3A%22cjs%22%2C%22minify%22%3Afalse%2C%22platform%22%3A%22neutral%22%7D%7D) +* [streams-text-encoding/text-decoder-stream](https://bundlejs.com/?q=%40stardazed%2Fstreams-text-encoding&treeshake=%5B%7B+TextDecoderStream+%7D%5D&config=%7B%22esbuild%22%3A%7B%22format%22%3A%22cjs%22%2C%22minify%22%3Afalse%7D%7D) + +> [!NOTE] +> The vendored implementation of `TextDecoderStream` requires +> the following patch to be applied to the output of bundlejs.com: +> +> ```diff +> constructor(label, options) { +> - this[decDecoder] = new TextDecoder(label, options); +> - this[decTransform] = new TransformStream(new TextDecodeTransformer(this[decDecoder])); +> + const decoder = new TextDecoder(label || "utf-8", options || {}); +> + this[decDecoder] = decoder; +> + this[decTransform] = new TransformStream(new TextDecodeTransformer(decoder)); +> } +> ``` diff --git a/README.md b/README.md index 6c27ef3..d89dd8d 100644 --- a/README.md +++ b/README.md @@ -1020,27 +1020,4 @@ const response = await replicate.request(route, parameters); The `replicate.request()` method is used by the other methods to interact with the Replicate API. -You can call this method directly to make other requests to the API. - -## Vendored Dependencies - -We have a few dependencies that have been bundled into the vendor directory rather than adding external npm dependencies. - -These have been generated using bundlejs.com and copied into the appropriate directory along with the license and repository information. - -* [eventsource-parser/stream](https://bundlejs.com/?bundle&q=eventsource-parser%40latest%2Fstream&config=%7B%22esbuild%22%3A%7B%22format%22%3A%22cjs%22%2C%22minify%22%3Afalse%2C%22platform%22%3A%22neutral%22%7D%7D) -* [streams-text-encoding/text-decoder-stream](https://bundlejs.com/?q=%40stardazed%2Fstreams-text-encoding&treeshake=%5B%7B+TextDecoderStream+%7D%5D&config=%7B%22esbuild%22%3A%7B%22format%22%3A%22cjs%22%2C%22minify%22%3Afalse%7D%7D) - -> [!NOTE] -> The vendored implementation of `TextDecoderStream` requires -> the following patch to be applied to the output of bundlejs.com: -> -> ```diff -> constructor(label, options) { -> - this[decDecoder] = new TextDecoder(label, options); -> - this[decTransform] = new TransformStream(new TextDecodeTransformer(this[decDecoder])); -> + const decoder = new TextDecoder(label || "utf-8", options || {}); -> + this[decDecoder] = decoder; -> + this[decTransform] = new TransformStream(new TextDecodeTransformer(decoder)); -> } -> ``` +You can call this method directly to make other requests to the API. \ No newline at end of file From 6fceb2fa311a0a7ceb1cf0a0bf001d9695f05cdd Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Thu, 23 May 2024 09:41:48 -0700 Subject: [PATCH 3/3] add a troubleshooting section to README first item: Next.js noStore --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d89dd8d..29c31c6 100644 --- a/README.md +++ b/README.md @@ -1020,4 +1020,19 @@ const response = await replicate.request(route, parameters); The `replicate.request()` method is used by the other methods to interact with the Replicate API. -You can call this method directly to make other requests to the API. \ No newline at end of file +You can call this method directly to make other requests to the API. + +## Troubleshooting + +### Predictions hanging in Next.js + +Next.js App Router adds some extensions to `fetch` to make it cache responses. To disable this behavior, set the `cache` option to `"no-store"` on the Replicate client's fetch object: + +```js +replicate = new Replicate({/*...*/}) +replicate.fetch = (url, options) => { + return fetch(url, { ...options, cache: "no-store" }); +}; +``` + +Alternatively you can use Next.js [`noStore`](https://github.com/replicate/replicate-javascript/issues/136#issuecomment-1847442879) to opt out of caching for your component.