Skip to content

Commit

Permalink
Revert "feat: use Streaming SSR"
Browse files Browse the repository at this point in the history
This reverts commit a8d7f3f.

Due to remix-run/remix#2947
  • Loading branch information
Ponjimon committed May 14, 2022
1 parent 5efa7f0 commit 418b365
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 70 deletions.
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
@@ -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
@@ -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
@@ -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
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
@@ -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
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

0 comments on commit 418b365

Please sign in to comment.