Skip to content
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

docs(start/v2): mention removed polyfills #7435

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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