Skip to content

Commit

Permalink
Update README with troubleshooting section (#264)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zeke committed May 28, 2024
1 parent 3db8800 commit e059286
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
23 changes: 23 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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));
> }
> ```
34 changes: 12 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1020,29 +1022,17 @@ 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.
## Troubleshooting

## Vendored Dependencies
### Predictions hanging in Next.js

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

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)
```js
replicate = new Replicate({/*...*/})
replicate.fetch = (url, options) => {
return fetch(url, { ...options, cache: "no-store" });
};
```

> [!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));
> }
> ```
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 comments on commit e059286

Please sign in to comment.