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

[examples] Updated Remix examples with the lates changes using React 18 #35092

Merged
merged 3 commits into from Nov 24, 2022

Conversation

58bits
Copy link
Contributor

@58bits 58bits commented Nov 10, 2022

From #34991

This should 'just work' with the updated entry.client.tsx for Remix latest and React 18

Note that the latest entry.server.tsx in the Remix blog tutorial uses renderToPipeableStream, although based on emotion-js/emotion#2800 - I'm not sure this is possible yet.

For interest only, below is what the renderToPipeableStream would look like in entry.server.tsx if it were supported.

Hope this helps.

import { PassThrough } from "stream";
import type { EntryContext } from "@remix-run/node";
import { Response } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
import isbot from "isbot";
import { renderToPipeableStream } from "react-dom/server";

const ABORT_DELAY = 5000;

export default function handleRequest(
  request: Request,
  responseStatusCode: number,
  responseHeaders: Headers,
  remixContext: EntryContext
) {
  const callbackName = isbot(request.headers.get("user-agent"))
    ? "onAllReady"
    : "onShellReady";

  return new Promise((resolve, reject) => {
    let didError = false;

    const { pipe, abort } = renderToPipeableStream(
      <RemixServer context={remixContext} url={request.url} />,
      {
        [callbackName]: () => {
          const body = new PassThrough();

          responseHeaders.set("Content-Type", "text/html");

          resolve(
            new Response(body, {
              headers: responseHeaders,
              status: didError ? 500 : responseStatusCode,
            })
          );

          pipe(body);
        },
        onShellError: (err: unknown) => {
          reject(err);
        },
        onError: (error: unknown) => {
          didError = true;

          console.error(error);
        },
      }
    );

    setTimeout(abort, ABORT_DELAY);
  });
}

@mui-bot
Copy link

mui-bot commented Nov 10, 2022

Messages
📖 Netlify deploy preview: https://deploy-preview-35092--material-ui.netlify.app/

No bundle size changes

Generated by 🚫 dangerJS against 0a9c893

@zannager zannager added the package: system Specific to @mui/system label Nov 11, 2022
@mnajdova
Copy link
Member

Looks like this works. BTW could you reference what project you used as a reference. I am asking because the Remix's emotion example is still using React 17 and some older implementaiton.

@58bits
Copy link
Contributor Author

58bits commented Nov 14, 2022

Hi @mnajdova - you know I searched (albeit fairly quickly) to find the new 'quickstart' app repo for Remix (not the Emotion example) - but couldn't find it. However, when you run this command npx create-remix@latest --template remix-run/indie-stack blog-tutorial from this page... https://remix.run/docs/en/v1/tutorials/blog - you get the latest indie stack with React 18. It's from this that I created the updated entry.client.tsx file, and configured the rest of the project for MUI 5 / Emotion.js (based on the Remix example here in the MUI repo)

@mnajdova
Copy link
Member

Hi @mnajdova - you know I searched (albeit fairly quickly) to find the new 'quickstart' app repo for Remix (not the Emotion example) - but couldn't find it. However, when you run this command npx create-remix@latest --template remix-run/indie-stack blog-tutorial from this page... https://remix.run/docs/en/v1/tutorials/blog - you get the latest indie stack with React 18. It's from this that I created the updated entry.client.tsx file, and configured the rest of the project for MUI 5 / Emotion.js (based on the Remix example here in the MUI repo)

Alright, this makes sense 👍 I guess their examples are not updated yet. I couldn't find anything out of place.

@mnajdova mnajdova changed the title updated entry.client.tsx for Remix latest and React 18 [examples] Updated Remix examples with the lates changes using React 18 Nov 16, 2022
@58bits
Copy link
Contributor Author

58bits commented Nov 16, 2022

just committed eslint and prettier fixes (apologies, commit messages are not 'conventional commits' - which I see now is the project's format)

@mnajdova
Copy link
Member

just committed eslint and prettier fixes (apologies, commit messages are not 'conventional commits' - which I see now is the project's format)

No worries, we squash and merge, so only one commit per PR is visible afterwards :) Thanks for fixing the issues

@mnajdova mnajdova merged commit db24f41 into mui:master Nov 24, 2022
daniel-rabe pushed a commit to daniel-rabe/material-ui that referenced this pull request Nov 29, 2022
feliperli pushed a commit to jesrodri/material-ui that referenced this pull request Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: system Specific to @mui/system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants