rive-app / rive-app/rive-react

I'm currently facing an issue when using @rive-app/react-canvas in a ReactJS Module Federation setup (Webpack as host and Vite as remote)

Open
#351 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
TypeScript
Stars
1.2k
Forks
58
Avg merge
3h 23m
Merged PRs (30d)
6

Description

Hi, I'm encountering a problem when trying to use @rive-app/react-canvas in a micro-frontend architecture where the host application is built with Webpack and the remote module is built with Vite. Here's a brief overview of my setup:

Webpack (Host) – webpack.config.js:

new ModuleFederationPlugin({
  name: "webpackHost",
  filename: "remoteEntry.js",
  remotes: {
    "@herond-point": "promise import("http://localhost:3001/assets/remoteEntry.js")",
  },
  shared: {
    react: {
      eager: true,
      import: "react",
      shareKey: "react",
      shareScope: "default",
      singleton: true,
    },
    "react-dom": {
      eager: true,
      import: "react-dom",
      shareKey: "react-dom",
      shareScope: "default",
      singleton: true,
    },
  },
})

Vite (Remote) – vite.config.ts:

 optimizeDeps: {
  include: ['@radix-ui/react-primitive', '@radix-ui/themes', 'react-redux', '@reduxjs/toolkit'],
},
build: {
  modulePreload: false,
  target: 'esnext',
  minify: false,
  cssCodeSplit: false,
  rollupOptions: {
    output: {
      minifyInternalExports: false,
      assetFileNames: (assetInfo) => {
        const ext = assetInfo.name?.split('.').pop();
        if (ext === 'svg') {
          return 'assets/icons/[name]-[hash][extname]';
        }
        return 'assets/[name]-[hash][extname]';
      },
    },
  },
},

publicDir: 'dist',

plugins: [
  react({ plugins: [['@swc/plugin-styled-components', {}]] }),
  macros(),
  svgr(),
  tsconfigPaths(),
  federation({
    name: '@herond-point',
    filename: 'remoteEntry.js',
    exposes: {
      './app': './src/AppRemote.tsx',
    },
    shared: {
      react: { requiredVersion: dependencies['react'] },
      'react-dom': { requiredVersion: dependencies['react-dom'] },
    },
  }),
]

Error Details:

When loading a remote component that uses @rive-app/react-canvas, I receive the following runtime error in the browser console:

herond_point.bundle.js:2 
TypeError: Cannot read properties of null (reading 'useState')
    at react_production_min.useState (index-B1oEREHO.js:262:21)
    at Object.O [as useRive] (index-BQu3j2DS.js:7128:16)
    at MysteryPotReward (index-BQu3j2DS.js:7265:19)
    at gi (herond_point.bundle.js:2:128737)
    at ws (herond_point.bundle.js:2:187678)
    at vu (herond_point.bundle.js:2:176930)
    at _u (herond_point.bundle.js:2:176858)
    at gu (herond_point.bundle.js:2:176721)
    at su (herond_point.bundle.js:2:173883)
    at jo (herond_point.bundle.js:2:115113)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare the host webpack.config.js and remote vite.config.ts federation settings, then inspect the exposed src/AppRemote.tsx path and the useRive stack shown in the error. Reproduce the Webpack-host/Vite-remote setup with @rive-app/react-canvas and verify that the remote component loads without the null useState runtime error.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript, vite, webpack
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.