Skip to content

chore(react): export createRemoteComponent and related utils #3847

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

2heal1
Copy link
Member

@2heal1 2heal1 commented Jun 16, 2025

Description

  • Remove createRemoteComponent and createRemoteSSRComponent from modern.js
  • Rename createRemoteComponent to createRemoteAppComponent in bridge
  • export createRemoteComponent and related utils from @module-federation/bridge-react
  • Rename createRemoteComponent to createLazyComponent in modern.js

For csr, users can import the apis from @module-federation/bridge-react directly:

import { registerPlugins  } from '@module-federation/enhanced/runtime';
import * as runtime from '@module-federation/enhanced/runtime';
import { createLazyComponent, injectDataFetch, autoFetchDataPlugin, ERROR_TYPE, type DataFetchParams } from '@module-federation/bridge-react';


// init manually
registerPlugins([autoFetchDataPlugin]);
injectDataFetch();

const List = createLazyComponent({
  // note: this is required!
  runtime,
  loader: () => {
    return import('remote/List');
  },
  loading: 'loading...',
  export: 'default',
  fallback: ({error,errorType,dataFetchMapKey}) => {
    console.error(error)
    if(errorType === ERROR_TYPE.LOAD_REMOTE){
      return <div>load remote failed</div>
    }
    if(errorType === ERROR_TYPE.DATA_FETCH){
      return <div>data fetch failed, the dataFetchMapKey key is: {dataFetchMapKey}</div>
    }
    return <div>error type is unknown</div>;
  },
});

const Index = (): JSX.Element => {
  return (
    <div>
      <h1>Basic usage with data fetch</h1>
      <List />
    </div>
  );
};

But for ssr, it still need to run in modern.js

Related Issue

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation.

Copy link

changeset-bot bot commented Jun 16, 2025

🦋 Changeset detected

Latest commit: eb0d1dc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 32 packages
Name Type
@module-federation/bridge-react Major
@module-federation/modern-js Major
@module-federation/bridge-vue3 Major
remote5 Patch
@module-federation/runtime Major
@module-federation/enhanced Major
@module-federation/rspack Major
@module-federation/webpack-bundler-runtime Major
@module-federation/sdk Major
@module-federation/runtime-tools Major
@module-federation/managers Major
@module-federation/manifest Major
@module-federation/dts-plugin Major
@module-federation/third-party-dts-extractor Major
@module-federation/devtools Major
@module-federation/bridge-shared Major
@module-federation/bridge-react-webpack-plugin Major
@module-federation/retry-plugin Major
@module-federation/data-prefetch Major
@module-federation/rsbuild-plugin Major
@module-federation/error-codes Major
@module-federation/inject-external-runtime-core-plugin Major
@module-federation/runtime-core Major
create-module-federation Major
@module-federation/cli Major
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/storybook-addon Major
@module-federation/modernjsapp Patch
@module-federation/esbuild Patch
@module-federation/utilities Patch
website-new Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Jun 16, 2025

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit eb0d1dc
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/68527f426d9a0d0008d2f4a4
😎 Deploy Preview https://deploy-preview-3847--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@2heal1 2heal1 force-pushed the chore/export-react-api branch from aa058ca to 02ce049 Compare June 16, 2025 12:17
@2heal1 2heal1 force-pushed the chore/export-react-api branch from 02ce049 to d1dd548 Compare June 16, 2025 12:19
@2heal1 2heal1 changed the title chore(bridge-react): export createRemoteComponent and related utils chore(react): export createRemoteComponent and related utils Jun 17, 2025
"@types/react": "18.2.79",
"react": "18.3.1",
"typescript": "^5.2.2",
"@modern-js/module-tools": "2.67.6",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using rslib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants