Skip to content

Commit e059286

Browse files
authored
Update README with troubleshooting section (#264)
* merge two typescript headings into one * move note about vendored deps to CONTRIBUTING docs * add a troubleshooting section to README first item: Next.js noStore
1 parent 3db8800 commit e059286

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

CONTRIBUTING.md

+23
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,26 @@ This will:
3232
- Push the commit and tag to GitHub
3333
- Publish the package to npm
3434
- Create a GitHub release
35+
36+
## Vendored Dependencies
37+
38+
We have a few dependencies that have been bundled into the vendor directory rather than adding external npm dependencies.
39+
40+
These have been generated using bundlejs.com and copied into the appropriate directory along with the license and repository information.
41+
42+
* [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)
43+
* [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)
44+
45+
> [!NOTE]
46+
> The vendored implementation of `TextDecoderStream` requires
47+
> the following patch to be applied to the output of bundlejs.com:
48+
>
49+
> ```diff
50+
> constructor(label, options) {
51+
> - this[decDecoder] = new TextDecoder(label, options);
52+
> - this[decTransform] = new TransformStream(new TextDecodeTransformer(this[decDecoder]));
53+
> + const decoder = new TextDecoder(label || "utf-8", options || {});
54+
> + this[decDecoder] = decoder;
55+
> + this[decTransform] = new TransformStream(new TextDecodeTransformer(decoder));
56+
> }
57+
> ```

README.md

+12-22
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ export async function POST(request) {
197197

198198
## TypeScript
199199

200+
The `Replicate` constructor and all `replicate.*` methods are fully typed.
201+
200202
Currently in order to support the module format used by `replicate` you'll need to set `esModuleInterop` to `true` in your tsconfig.json.
201203

202204
## API
@@ -1020,29 +1022,17 @@ The `replicate.request()` method is used by the other methods
10201022
to interact with the Replicate API.
10211023
You can call this method directly to make other requests to the API.
10221024

1023-
## TypeScript
1024-
1025-
The `Replicate` constructor and all `replicate.*` methods are fully typed.
1025+
## Troubleshooting
10261026

1027-
## Vendored Dependencies
1027+
### Predictions hanging in Next.js
10281028

1029-
We have a few dependencies that have been bundled into the vendor directory rather than adding external npm dependencies.
1029+
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:
10301030

1031-
These have been generated using bundlejs.com and copied into the appropriate directory along with the license and repository information.
1032-
1033-
* [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)
1034-
* [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)
1031+
```js
1032+
replicate = new Replicate({/*...*/})
1033+
replicate.fetch = (url, options) => {
1034+
return fetch(url, { ...options, cache: "no-store" });
1035+
};
1036+
```
10351037

1036-
> [!NOTE]
1037-
> The vendored implementation of `TextDecoderStream` requires
1038-
> the following patch to be applied to the output of bundlejs.com:
1039-
>
1040-
> ```diff
1041-
> constructor(label, options) {
1042-
> - this[decDecoder] = new TextDecoder(label, options);
1043-
> - this[decTransform] = new TransformStream(new TextDecodeTransformer(this[decDecoder]));
1044-
> + const decoder = new TextDecoder(label || "utf-8", options || {});
1045-
> + this[decDecoder] = decoder;
1046-
> + this[decTransform] = new TransformStream(new TextDecodeTransformer(decoder));
1047-
> }
1048-
> ```
1038+
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.

0 commit comments

Comments
 (0)