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

[system] Updated entry.client.tsx for remix-with-typescript example app #34991

Closed
58bits opened this issue Nov 2, 2022 · 4 comments
Closed
Assignees
Labels
enhancement This is not a bug, nor a new feature package: system Specific to @mui/system

Comments

@58bits
Copy link
Contributor

58bits commented Nov 2, 2022

Would be happy to submit this as a PR as well...

Here's an updated entry.client.tsx file for the remix-with-typescript example app, based on the latest Remix QuickStart and React 18 (using hyrdrateRoot as opposed to hydrate)

Not sure about entry.server.tsx yet as emotion does not support renderToPipeableStream?

emotion-js/emotion#2800

import React, { useState} from 'react'
import { RemixBrowser } from "@remix-run/react";
import { startTransition, StrictMode } from "react";
import { hydrateRoot } from "react-dom/client";
import { CacheProvider } from '@emotion/react';
import { ThemeProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import ClientStyleContext from './ClientStyleContext';
import createEmotionCache from './createEmotionCache';
import theme from './theme';

interface ClientCacheProviderProps {
  children: React.ReactNode;
}

function ClientCacheProvider({ children }: ClientCacheProviderProps) {
  const [cache, setCache] = useState(createEmotionCache());

  const clientStyleContextValue = React.useMemo(
    () => ({
      reset() {
        setCache(createEmotionCache());
      },
    }),
    [],
  );

  return (
    <ClientStyleContext.Provider value={clientStyleContextValue}>
      <CacheProvider value={cache}>{children}</CacheProvider>
    </ClientStyleContext.Provider>
  );
}

const hydrate = () => {
  startTransition(() => {
    hydrateRoot(
      document,
      <ClientCacheProvider>
        <ThemeProvider theme={theme}>
          {/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
          <CssBaseline />
          <StrictMode>
            <RemixBrowser />
          </StrictMode>
        </ThemeProvider>
      </ClientCacheProvider>,
    );
  });
};

if (window.requestIdleCallback) {
  window.requestIdleCallback(hydrate);
} else {
  // Safari doesn't support requestIdleCallback
  // https://caniuse.com/requestidlecallback
  window.setTimeout(hydrate, 1);
}
@zannager zannager added status: waiting for maintainer These issues haven't been looked at yet by a maintainer package: system Specific to @mui/system labels Nov 3, 2022
@hbjORbj hbjORbj changed the title Updated entry.client.tsx for remix-with-typescript example app [system] Updated entry.client.tsx for remix-with-typescript example app Nov 3, 2022
@mnajdova
Copy link
Member

Thanks @58bits would you like to create a PR with the proposed changes, so that we can change the example as a whole?

@mnajdova mnajdova added enhancement This is not a bug, nor a new feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 10, 2022
@58bits
Copy link
Contributor Author

58bits commented Nov 10, 2022

@mnajdova - sure!

@58bits
Copy link
Contributor Author

58bits commented Nov 10, 2022

@mnajdova - #35092

@mnajdova
Copy link
Member

Thanks! I will test it out next week and provide feedback on the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is not a bug, nor a new feature package: system Specific to @mui/system
Projects
None yet
Development

No branches or pull requests

4 participants