Skip to content

Commit

Permalink
chore: skip script rendering after hydration (#422)
Browse files Browse the repository at this point in the history
Should be what we need for preact support
  • Loading branch information
developit authored Dec 15, 2021
1 parent caed1f0 commit d4860a0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ yarn-error.log
/fixtures/test
/fixtures/my-remix-app
/fixtures/deno-app
/fixtures/my-remix-app

.eslintcache
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- coryhouse
- davecalnan
- derekr
- developit
- dunglas
- dwt47
- edgesoft
Expand Down
12 changes: 11 additions & 1 deletion packages/remix-react/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,12 @@ export function Meta() {
);
}

/**
* Tracks whether Remix has finished hydrating or not, so scripts can be skipped
* during client-side updates.
*/
let isHydrated = false;

type ScriptProps = Omit<
React.HTMLProps<HTMLScriptElement>,
| "children"
Expand Down Expand Up @@ -687,6 +693,10 @@ export function Scripts(props: ScriptProps) {
serverHandoffString
} = useRemixEntryContext();

React.useEffect(() => {
isHydrated = true;
}, []);

let initialScripts = React.useMemo(() => {
let contextScript = serverHandoffString
? `window.__remixContext = ${serverHandoffString};`
Expand Down Expand Up @@ -758,7 +768,7 @@ window.__remixRouteModules = {${matches
crossOrigin={props.crossOrigin}
/>
))}
{initialScripts}
{isHydrated ? null : initialScripts}
</>
);
}
Expand Down

0 comments on commit d4860a0

Please sign in to comment.