Skip to content

Commit

Permalink
feat(remix-react): unblock hydration via async module scripts (#3918)
Browse files Browse the repository at this point in the history
* feat: unblock hydration via async module scripts

* flatten manifest into async module script
  • Loading branch information
jacob-ebey authored Aug 12, 2022
1 parent 5987c9e commit b526aee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 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.
16 changes: 12 additions & 4 deletions packages/remix-react/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -807,29 +807,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 @@ -862,6 +865,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 b526aee

Please sign in to comment.