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

Fix TS error in entry-server - make Passthrough a ReadableStream #7361

Merged
merged 5 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/lovely-suits-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

[REMOVE] Fix TS error in entry.server.tsx to make PassThrough body a ReadableStream
12 changes: 9 additions & 3 deletions docs/guides/migrating-react-router-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Let's start by creating two new files:
<docs-info>All of your app code in Remix will live in an `app` directory by convention. If your existing app uses a directory with the same name, rename it to something like `src` or `old-app` to differentiate as we migrate to Remix.</docs-info>

```tsx filename=app/entry.server.tsx
import { PassThrough } from "node:stream";
import { Readable, PassThrough } from "node:stream";

import type {
AppLoadContext,
Expand Down Expand Up @@ -96,11 +96,14 @@ function handleBotRequest(
{
onAllReady() {
const body = new PassThrough();
const webBody = Readable.toWeb(
body
) as ReadableStream;

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

resolve(
new Response(body, {
new Response(webBody, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down Expand Up @@ -138,11 +141,14 @@ function handleBrowserRequest(
{
onShellReady() {
const body = new PassThrough();
const webBody = Readable.toWeb(
body
) as ReadableStream;

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

resolve(
new Response(body, {
new Response(webBody, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down
8 changes: 5 additions & 3 deletions packages/remix-dev/config/defaults/entry.server.node.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PassThrough } from "node:stream";
import { Readable, PassThrough } from "node:stream";

import type { AppLoadContext, EntryContext } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
Expand Down Expand Up @@ -47,11 +47,12 @@ function handleBotRequest(
onAllReady() {
shellRendered = true;
const body = new PassThrough();
const webBody = Readable.toWeb(body) as ReadableStream;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cast seems to be required due to the underlying generic, but I couldn't find a way to get them to align without the as.

Type 'ReadableStream<T>' is missing the following properties from type 'ReadableStream<ArrayBufferView | undefined>': 
  values, [Symbol.asyncIterator]ts(2345)


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

resolve(
new Response(body, {
new Response(webBody, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down Expand Up @@ -96,11 +97,12 @@ function handleBrowserRequest(
onShellReady() {
shellRendered = true;
const body = new PassThrough();
const webBody = Readable.toWeb(body) as ReadableStream;

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

resolve(
new Response(body, {
new Response(webBody, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down
5 changes: 3 additions & 2 deletions scripts/playground/template/app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PassThrough } from "node:stream";
import { Readable, PassThrough } from "node:stream";
import type { AppLoadContext, EntryContext } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
import isbot from "isbot";
Expand Down Expand Up @@ -29,11 +29,12 @@ export default function handleRequest(
{
[callbackName]: () => {
let body = new PassThrough();
let webBody = Readable.toWeb(body) as ReadableStream;

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

resolve(
new Response(body, {
new Response(webBody, {
headers: responseHeaders,
status: didError ? 500 : responseStatusCode,
})
Expand Down
8 changes: 5 additions & 3 deletions templates/arc/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* For more information, see https://remix.run/file-conventions/entry.server
*/

import { PassThrough } from "node:stream";
import { Readable, PassThrough } from "node:stream";

import type { AppLoadContext, EntryContext } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
Expand Down Expand Up @@ -53,11 +53,12 @@ function handleBotRequest(
onAllReady() {
shellRendered = true;
const body = new PassThrough();
const webBody = Readable.toWeb(body) as ReadableStream;

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

resolve(
new Response(body, {
new Response(webBody, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down Expand Up @@ -102,11 +103,12 @@ function handleBrowserRequest(
onShellReady() {
shellRendered = true;
const body = new PassThrough();
const webBody = Readable.toWeb(body) as ReadableStream;

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

resolve(
new Response(body, {
new Response(webBody, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down
8 changes: 5 additions & 3 deletions templates/express/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* For more information, see https://remix.run/file-conventions/entry.server
*/

import { PassThrough } from "node:stream";
import { Readable, PassThrough } from "node:stream";

import type { AppLoadContext, EntryContext } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
Expand Down Expand Up @@ -53,11 +53,12 @@ function handleBotRequest(
onAllReady() {
shellRendered = true;
const body = new PassThrough();
const webBody = Readable.toWeb(body) as ReadableStream;

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

resolve(
new Response(body, {
new Response(webBody, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down Expand Up @@ -102,11 +103,12 @@ function handleBrowserRequest(
onShellReady() {
shellRendered = true;
const body = new PassThrough();
const webBody = Readable.toWeb(body) as ReadableStream;

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

resolve(
new Response(body, {
new Response(webBody, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down
8 changes: 5 additions & 3 deletions templates/fly/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* For more information, see https://remix.run/file-conventions/entry.server
*/

import { PassThrough } from "node:stream";
import { Readable, PassThrough } from "node:stream";

import type { AppLoadContext, EntryContext } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
Expand Down Expand Up @@ -53,11 +53,12 @@ function handleBotRequest(
onAllReady() {
shellRendered = true;
const body = new PassThrough();
const webBody = Readable.toWeb(body) as ReadableStream;

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

resolve(
new Response(body, {
new Response(webBody, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down Expand Up @@ -102,11 +103,12 @@ function handleBrowserRequest(
onShellReady() {
shellRendered = true;
const body = new PassThrough();
const webBody = Readable.toWeb(body) as ReadableStream;

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

resolve(
new Response(body, {
new Response(webBody, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down
8 changes: 5 additions & 3 deletions templates/remix-javascript/app/entry.server.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* For more information, see https://remix.run/docs/en/main/file-conventions/entry.server
*/

import { PassThrough } from "node:stream";
import { Readable, PassThrough } from "node:stream";

import { RemixServer } from "@remix-run/react";
import isbot from "isbot";
Expand Down Expand Up @@ -49,11 +49,12 @@ function handleBotRequest(
{
onAllReady() {
const body = new PassThrough();
const webBody = Readable.toWeb(body);

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

resolve(
new Response(body, {
new Response(webBody, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down Expand Up @@ -91,11 +92,12 @@ function handleBrowserRequest(
{
onShellReady() {
const body = new PassThrough();
const webBody = Readable.toWeb(body);

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

resolve(
new Response(body, {
new Response(webBody, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down
8 changes: 5 additions & 3 deletions templates/remix/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* For more information, see https://remix.run/file-conventions/entry.server
*/

import { PassThrough } from "node:stream";
import { Readable, PassThrough } from "node:stream";

import type { AppLoadContext, EntryContext } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
Expand Down Expand Up @@ -53,11 +53,12 @@ function handleBotRequest(
onAllReady() {
shellRendered = true;
const body = new PassThrough();
const webBody = Readable.toWeb(body) as ReadableStream;

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

resolve(
new Response(body, {
new Response(webBody, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down Expand Up @@ -102,11 +103,12 @@ function handleBrowserRequest(
onShellReady() {
shellRendered = true;
const body = new PassThrough();
const webBody = Readable.toWeb(body) as ReadableStream;

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

resolve(
new Response(body, {
new Response(webBody, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down