generated from edmundhung/remix-cloudflare-template
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: enable streaming * fix: lint warning * fix: tag search * feat: enable filters on rss
- Loading branch information
1 parent
2a47b88
commit b2b563e
Showing
12 changed files
with
166 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,6 @@ jobs: | |
name: 🔍 Testing | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 🛑 Cancel Previous Runs | ||
uses: styfle/[email protected] | ||
- name: ⬇️ Checkout repo | ||
uses: actions/checkout@v3 | ||
- name: ⎔ Setup node | ||
|
@@ -27,8 +25,6 @@ jobs: | |
name: ⬣ Linting | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 🛑 Cancel Previous Runs | ||
uses: styfle/[email protected] | ||
- name: ⬇️ Checkout repo | ||
uses: actions/checkout@v3 | ||
- name: ⎔ Setup node | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,22 @@ | ||
import ReactDOM from 'react-dom'; | ||
import { RemixBrowser } from '@remix-run/react'; | ||
import { startTransition, StrictMode } from 'react'; | ||
import { hydrateRoot } from 'react-dom/client'; | ||
|
||
ReactDOM.hydrate(<RemixBrowser />, document); | ||
function hydrate() { | ||
startTransition(() => { | ||
hydrateRoot( | ||
document, | ||
<StrictMode> | ||
<RemixBrowser /> | ||
</StrictMode>, | ||
); | ||
}); | ||
} | ||
|
||
if (window.requestIdleCallback) { | ||
window.requestIdleCallback(hydrate); | ||
} else { | ||
// Safari doesn't support requestIdleCallback | ||
// https://caniuse.com/requestidlecallback | ||
window.setTimeout(hydrate, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,34 @@ | ||
import ReactDOMServer from 'react-dom/server'; | ||
import type { EntryContext } from '@remix-run/cloudflare'; | ||
import { type EntryContext } from '@remix-run/cloudflare'; | ||
import { RemixServer } from '@remix-run/react'; | ||
import isbot from 'isbot'; | ||
import { renderToReadableStream } from 'react-dom/server'; | ||
|
||
export default function handleRequest( | ||
export default async function handleRequest( | ||
request: Request, | ||
responseStatusCode: number, | ||
responseHeaders: Headers, | ||
remixContext: EntryContext, | ||
) { | ||
let markup = ReactDOMServer.renderToString( | ||
const body = await renderToReadableStream( | ||
<RemixServer context={remixContext} url={request.url} />, | ||
{ | ||
onError: (error) => { | ||
responseStatusCode = 500; | ||
console.error(error); | ||
}, | ||
signal: request.signal, | ||
}, | ||
); | ||
|
||
responseHeaders.set('Content-Type', 'text/html'); | ||
if (isbot(request.headers.get('User-Agent'))) { | ||
await body.allReady; | ||
} | ||
|
||
return new Response('<!DOCTYPE html>' + markup, { | ||
const headers = new Headers(responseHeaders); | ||
headers.set('Content-Type', 'text/html'); | ||
|
||
return new Response(body, { | ||
status: responseStatusCode, | ||
headers: responseHeaders, | ||
headers, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.