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

feat(remix-react): unblock hydration via async module scripts #3918

Merged
merged 3 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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: 5 additions & 0 deletions .changeset/wild-meals-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/react": patch
---

Unblock hydration via use of async module scripts.
16 changes: 12 additions & 4 deletions packages/remix-react/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -796,29 +796,32 @@ export function Scripts(props: ScriptProps) {
let routeModulesScript = `${matches
.map(
(match, index) =>
`import * as route${index} from ${JSON.stringify(
`import ${JSON.stringify(manifest.url)};
import * as route${index} from ${JSON.stringify(
manifest.routes[match.route.id].module
)};`
)
.join("\n")}
window.__remixRouteModules = {${matches
.map((match, index) => `${JSON.stringify(match.route.id)}:route${index}`)
.join(",")}};`;
.join(",")}};

import(${JSON.stringify(manifest.entry.module)});`;

return (
<>
<script
{...props}
suppressHydrationWarning
dangerouslySetInnerHTML={createHtml(contextScript)}
type={undefined}
/>
<script {...props} src={manifest.url} />
<script
{...props}
dangerouslySetInnerHTML={createHtml(routeModulesScript)}
type="module"
async
/>
<script {...props} src={manifest.entry.module} type="module" />
</>
);
// disabled deps array because we are purposefully only rendering this once
Expand Down Expand Up @@ -851,6 +854,11 @@ window.__remixRouteModules = {${matches

return (
<>
<link
rel="modulepreload"
href={manifest.entry.module}
crossOrigin={props.crossOrigin}
/>
{dedupe(preloads).map((path) => (
<link
key={path}
Expand Down