Skip to content

Commit

Permalink
feat: unblock hydration via async module scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-ebey committed Aug 3, 2022
1 parent 79279b3 commit 984f454
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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.
14 changes: 11 additions & 3 deletions packages/remix-react/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -803,22 +803,25 @@ export function Scripts(props: ScriptProps) {
.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} type={undefined} 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

0 comments on commit 984f454

Please sign in to comment.