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

wip: attempt at preact hydration support #403

Closed
wants to merge 1 commit into from

Conversation

jacob-ebey
Copy link
Member

No description provided.

@@ -691,6 +697,12 @@ export function Scripts(props: ScriptProps) {
serverHandoffString
} = useRemixEntryContext();

let hydratedRef = React.useRef(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this isn't used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is just a POC as I'm not a fan of the global variable here on window. I just wanted to prove that we can remove script tags after hydration for subsequent re-renders. This works as we load the context in the client entry component and that one never re-mounts as our error boundary logic is lower in the tree from there around each individual route.

let hydratedRef = React.useRef(false);

React.useEffect(() => {
window.remixIsHydrated = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's only ever one copy of components.tsx running on a page, so it should be possible to use a module variable here:

let isHydrated = false;

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

  React.useMemo(() => {
    // <snip>

    return (
      <>
        {dedupe(preloads).map(path => (
          <link
            key={path}
            rel="modulepreload"
            href={path}
            crossOrigin={props.crossOrigin}
          />
        ))}
        {initialScripts}
        {isHydrated ? null : initialScripts}
      </>
    );
  }, []);
}

@ryanflorence
Copy link
Member

superseded by #422

@jacob-ebey jacob-ebey deleted the jacob/script-hydration branch December 15, 2021 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants