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

[Feature]: Support Remix [SSR] #32825

Open
1 task done
it950 opened this issue Sep 13, 2024 · 14 comments
Open
1 task done

[Feature]: Support Remix [SSR] #32825

it950 opened this issue Sep 13, 2024 · 14 comments
Labels
Area: SSR Server-side rendering Fluent UI react-components (v9) Needs: PM Incoming shield issues that are feature type which require PM to review. Type: Feature

Comments

@it950
Copy link

it950 commented Sep 13, 2024

Library

React Components / v9 (@fluentui/react-components)

Describe the feature that you would like added

Does fluentui v9 support remix? how to do it?

Have you discussed this feature with our team

No

Additional context

No response

Validations

  • Check that there isn't already an issue that requests the same feature to avoid creating a duplicate.

Priority

None

@ValentinaKozlova
Copy link
Contributor

@it950, could you please give more details?

@it950
Copy link
Author

it950 commented Sep 13, 2024

In the remix document, css in js is not recommended, while fluentui v9 uses css in js technology. Therefore, can fluentui v9 be installed directly in remix? In addition, there is no introduction on how to use in remix in the fluent v9 document

@ValentinaKozlova
Copy link
Contributor

In the remix document, css in js is not recommended, while fluentui v9 uses css in js technology. Therefore, can fluentui v9 be installed directly in remix? In addition, there is no introduction on how to use in remix in the fluent v9 document

Have you tried to install it? And have you tried to follow instruction of using SSR in V9? If it's not working, please let me know what errors you have

@it950
Copy link
Author

it950 commented Sep 16, 2024

In the remix document, css in js is not recommended, while fluentui v9 uses css in js technology. Therefore, can fluentui v9 be installed directly in remix? In addition, there is no introduction on how to use in remix in the fluent v9 document

Have you tried to install it? And have you tried to follow instruction of using SSR in V9? If it's not working, please let me know what errors you have

I have created a remix start project only install @fluentui/react-components and @fluentui/react-icons,
and only change the code in the root.ts:

export default function App() {
  return (
    <FluentProvider theme={webLightTheme}>
      <Outlet />
    </FluentProvider>
  );
}

An error like the following:
image

How to setup a new remix project correctly that use a @fluent/react-components and @fluentui/react-icons ?

@it950 it950 reopened this Sep 16, 2024
@layershifter
Copy link
Member

The issue is that v9 does not support native ESM, see #26176 and #23508.


However, there is a workaround. Quoting myself from an internal chat:

Anyway, the source of the issue is that Fluent packages are bundled in a way that they does not really support native ESM:

// test.mjs
import { Button} from '@fluentui/react-components'
console.log(Button)

image

But it's solvable with Vite if we bundle some deps (https://vitejs.dev/config/ssr-options.html#ssr-noexternal), this was enough to make it alive:

export default defineConfig({
 plugins: [react()],
 ssr: {
   noExternal: /@fluentui|@swc|@floating-ui/,
 },
});

I also put some CSS rendering rendering config (check entry-* files), altogether is there: https://stackblitz.com/edit/bluwy-create-vite-extra-qnzeak

And seems to work, I believe that for Remix itself it would be something similar.
Edit: looks like it has own config https://remix.run/docs/en/main/guides/vite#configuration

And no, it won't work with Remix as they also use in dev Vite Runtime API 💥

I wrote a naive plugin that makes it work:

const fluentConfigPlugin: Plugin = {
 config(config, envConfig) {
   if (envConfig.mode === 'production') {
     return {
       ssr: {
         noExternal: /@fluentui|@swc|@floating-ui/,
       },
     };
   }

   return {
     legacy: {
       proxySsrExternalModules: true,
     },
   };
 },
};

With that - it should work for now, https://stackblitz.com/edit/remix-run-remix-i6tns1 🚀

@it950
Copy link
Author

it950 commented Sep 23, 2024

@layershifter Much appreciated! 😊

  1. I added @fluent/react-icons base on your demo:
    https://stackblitz.com/edit/remix-run-remix-bi2gcp?file=app%2Froutes%2Ftest.tsx
  2. And then add a test page in routes folder.

There is an error like this:
image

@layershifter
Copy link
Member

@it950 indeed, sadly @fluentui/react-icons don't have the same export maps as other packages:

"types": "./dist/index.d.ts",
"node": "./lib-commonjs/index.js",
"import": "./lib/index.js",
"require": "./lib-commonjs/index.js"

@it950
Copy link
Author

it950 commented Sep 23, 2024

don't have the same export maps as other packages:

the makeStyles function also can not run,
image

We are currently migrating v8 to v9, v8 used CRA before, and v9 uses nextjs at present. However, the speed of nextjs development environment is too slow, even with turbo, HRM loading is still very slow, so we want to test remix. but now remix is still hard to run with @fluentui/react-components, too many problems.

Can you give me some advice? Thank you

@layershifter
Copy link
Member

Can you give me some advice? Thank you

Hey, this requires a proper investigation and unfortunately I don't have capacity to do a proper investigation now :(

@layershifter layershifter changed the title [Feature]: Does fluent ui v9 support remix [Feature]: Support Remix [SSR] Sep 27, 2024
@layershifter layershifter added Area: SSR Server-side rendering Needs: PM Incoming shield issues that are feature type which require PM to review. labels Sep 27, 2024
@georgetakla
Copy link

@it950 regarding @fluentui/react-icons

@layershifter Much appreciated! 😊

  1. I added @fluent/react-icons base on your demo:
    https://stackblitz.com/edit/remix-run-remix-bi2gcp?file=app%2Froutes%2Ftest.tsx
  2. And then add a test page in routes folder.

There is an error like this: image

I used @layershifter idea of building a plugin and created one to fix the issues in this package ..

const fluentIconsFixPlugin: Plugin = {
  name: 'fluent-icons-fix-plugin',
  config(config, { mode }) {
    return {
      build: {
        rollupOptions: {
          output: {
            // Ensure files from @fluentui/react-icons are output correctly as ESM
            entryFileNames: (chunkInfo) => {
              if (chunkInfo.facadeModuleId && chunkInfo.facadeModuleId.includes('@fluentui/react-icons')) {
                return '[name].mjs'; // Use .mjs extension for ESM files
              }
              return '[name].js';
            },
          },
        },
      },
      ssr: {
        // Ensure @fluentui/react-icons is not treated as an external dependency during SSR
        noExternal: ['@fluentui/react-icons'],
      },
      optimizeDeps: {
        // Force Vite to pre-bundle @fluentui/react-icons as ESM
        include: ['@fluentui/react-icons'],
      },
    };
  },
};

I did not get the error, but not sure if the icons are displayed correctly ..
try it and let us know

@it950
Copy link
Author

it950 commented Oct 6, 2024

@georgetakla Thank you very much.
Now it can run directly, I will try to migrate the whole program(v8) to remix(v9), if there are some other questions, I will give feedback.

@georgetakla
Copy link

@it950 , I hope it worked for you. I ran into difficulties using the packages. I hope you have some success

@it950
Copy link
Author

it950 commented Oct 27, 2024

@georgetakla I have gave up migrating cra to remix, because there are a lot of others issues for fluent packages( such as peer dependencies )run with remixes, I am now waiting for the react route v7, which will include remix features in it

@r007
Copy link

r007 commented Nov 21, 2024

Check out my recipe #33317

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: SSR Server-side rendering Fluent UI react-components (v9) Needs: PM Incoming shield issues that are feature type which require PM to review. Type: Feature
Projects
None yet
Development

No branches or pull requests

5 participants