Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Sep 15, 2023
1 parent c525f10 commit 0e8a6a8
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions docs/start/v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,89 @@ import { installGlobals } from "@remix-run/node";
installGlobals();
```

### Removal of exported polyfills

Remix v2 also no longer exports these polyfilled implementations from `@remix-run/node`, and instead you should just use the instances in the global namespace. One place this is likely to surface and require a change is your `entry.server.tsx` file, where you'll also need to convert the Node `PassThrough` into a web `ReadableStream` via `createReadableStreamFromReadable`:

```diff
import { PassThrough } from "node:stream";
import type { AppLoadContext, EntryContext } from "@remix-run/node";
- import { Response } from "@remix-run/node";
+ import { createReadableStreamFromReadable } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
import isbot from "isbot";
import { renderToPipeableStream } from "react-dom/server";

const ABORT_DELAY = 5_000;

export default function handleRequest({ /* ... */ }) { ... }

function handleBotRequest(...) {
return new Promise((resolve, reject) => {
let shellRendered = false;
const { pipe, abort } = renderToPipeableStream(
<RemixServer ... />,
{
onAllReady() {
shellRendered = true;
const body = new PassThrough();
+ const stream = createReadableStreamFromReadable(body);

responseHeaders.set("Content-Type", "text/html");

resolve(
- new Response(body, {
+ new Response(stream, {
headers: responseHeaders,
status: responseStatusCode,
})
);

pipe(body);
},
...
onShellError(error: unknown) { ... }
onError(error: unknown) { ... }
}
);

setTimeout(abort, ABORT_DELAY);
});
}

function handleBrowserRequest(...) {
return new Promise((resolve, reject) => {
let shellRendered = false;
const { pipe, abort } = renderToPipeableStream(
<RemixServer ... />,
{
onShellReady() {
shellRendered = true;
const body = new PassThrough();
+ const stream = createReadableStreamFromReadable(body);

responseHeaders.set("Content-Type", "text/html");

resolve(
- new Response(body, {
+ new Response(stream, {
headers: responseHeaders,
status: responseStatusCode,
})
);

pipe(body);
},
onShellError(error: unknown) { ... },
onError(error: unknown) { ... },
}
);

setTimeout(abort, ABORT_DELAY);
});
}
```

## `source-map-support`

Source map support is now a responsibility of the app server. If you are using `remix-serve`, nothing is required. If you are using your own app server, you will need to install [`source-map-support`][source-map-support] yourself.
Expand Down

0 comments on commit 0e8a6a8

Please sign in to comment.