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

Revert "feat: use Streaming SSR" #5

Merged
merged 1 commit into from
May 14, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 0 additions & 5 deletions app/components/LazyLoaded.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions app/components/README.md

This file was deleted.

4 changes: 2 additions & 2 deletions app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hydrateRoot } from 'react-dom/client';
import { hydrate } from 'react-dom';
import { RemixBrowser } from '@remix-run/react';

hydrateRoot(document, <RemixBrowser />);
hydrate(<RemixBrowser />, document);
41 changes: 10 additions & 31 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,21 @@
import { renderToReadableStream } from 'react-dom/server';
import { renderToString } from 'react-dom/server';
import type { EntryContext } from '@remix-run/cloudflare';
import { RemixServer } from '@remix-run/react';
import isbot from 'isbot';

export default async function handleRequest(
export default function handleRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
remixContext: EntryContext
) {
const controller = new AbortController();
const markup = renderToString(
<RemixServer context={remixContext} url={request.url} />
);

try {
const stream = await renderToReadableStream(
<RemixServer context={remixContext} url={request.url} />,
{
signal: controller.signal,
onError: error => {
responseStatusCode = 500;
console.error(error);
},
}
);
responseHeaders.set('Content-Type', 'text/html');

if (isbot(request.headers.get('user-agent'))) {
await stream.allReady;
}

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

return new Response(stream, {
status: responseStatusCode,
headers: responseHeaders,
});
} catch (e) {
return new Response('<!doctype html><p>Loading...</p>', {
status: 500,
headers: { 'Content-Type': 'text/html' },
});
}
return new Response('<!DOCTYPE html>' + markup, {
status: responseStatusCode,
headers: responseHeaders,
});
}
22 changes: 0 additions & 22 deletions app/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
import { lazy, Suspense, useState } from 'react';

const LazyLoaded = lazy(async () => {
// Artificial delay
await new Promise(resolve => setTimeout(resolve, 1000));

return await import('../components/LazyLoaded');
});

export default function Index() {
const [showLazyLoaded, setShowLazyLoaded] = useState(false);

return (
<div style={{ fontFamily: 'system-ui, sans-serif', lineHeight: '1.4' }}>
<h1>Welcome to Remix</h1>
Expand Down Expand Up @@ -37,17 +26,6 @@ export default function Index() {
Remix Docs
</a>
</li>
<li>
{showLazyLoaded ? (
<Suspense fallback="Loading...">
<LazyLoaded />
</Suspense>
) : (
<button type="button" onClick={() => setShowLazyLoaded(true)}>
Click here to Lazy Load
</button>
)}
</li>
</ul>
</div>
);
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"@remix-run/cloudflare": "^1.4.3",
"@remix-run/cloudflare-pages": "^1.4.3",
"@remix-run/react": "^1.4.3",
"isbot": "^3.4.6",
"react": "^18.1.0",
"react-dom": "^18.1.0"
},
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],
"compilerOptions": {
"module": "es2020",
"lib": ["DOM", "DOM.Iterable", "ES2019"],
"isolatedModules": true,
"esModuleInterop": true,
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4379,11 +4379,6 @@ isarray@1.0.0, isarray@~1.0.0:
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=

isbot@^3.4.6:
version "3.4.6"
resolved "https://registry.yarnpkg.com/isbot/-/isbot-3.4.6.tgz#e3dd70034b6a6fad043753de71cd96929a678015"
integrity sha512-EEi3SVCPB4WHtMBaAYzYLgCP7yG9qixseYCf3IG0Yc+howLia+XFPLTT1437rzeViLeDInKOXOdFhs9Fa/xgWQ==

isexe@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
Expand Down