Repository navigation
feat(ui): support typed micro frontend placements and ESM remotes #21921
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
base: master
Are you sure you want to change the base?
Changes from all commits
237e7db
a308d52
a03814b
291734a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,28 @@ | ||||||||
| name: MFE runtime | ||||||||
| on: | ||||||||
| pull_request: | ||||||||
| paths: | ||||||||
| - "datahub-web-react/devtools/mfe-fixture/**" | ||||||||
| - "datahub-web-react/src/app/mfeframework/**" | ||||||||
| - "datahub-web-react/vite.config.ts" | ||||||||
| - "datahub-web-react/package.json" | ||||||||
| - "datahub-web-react/yarn.lock" | ||||||||
| - ".github/workflows/mfe-runtime.yml" | ||||||||
| permissions: | ||||||||
| contents: read | ||||||||
| jobs: | ||||||||
| browser: | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The Prompt for AI agents
Suggested change
|
||||||||
| runs-on: ubuntu-24.04 | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: Add Prompt for AI agents
Suggested change
|
||||||||
| defaults: | ||||||||
| run: | ||||||||
| working-directory: datahub-web-react | ||||||||
| steps: | ||||||||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||||||||
| - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 | ||||||||
| with: | ||||||||
| node-version: "22" | ||||||||
| cache: yarn | ||||||||
| cache-dependency-path: datahub-web-react/yarn.lock | ||||||||
| - run: yarn install --frozen-lockfile | ||||||||
| - run: npm ci --prefix devtools/mfe-fixture/remote --ignore-scripts | ||||||||
| - run: node devtools/mfe-fixture/build.mjs && python3 devtools/mfe-fixture/verify.py | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -333,6 +333,11 @@ module.exports = { | |
| }, | ||
| }, | ||
| overrides: [ | ||
| { | ||
| files: ['devtools/mfe-fixture/host/main.js'], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: This override never takes effect in CI: Prompt for AI agents |
||
| env: { browser: true }, | ||
| rules: { 'import/no-unresolved': ['error', { ignore: ['^virtual:__federation__$'] }] }, | ||
| }, | ||
| { | ||
| files: ['src/app/searchV2/**/*.tsx', 'src/app/entityV2/**/*.tsx'], | ||
| rules: { 'import/no-cycle': 'off' }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| build/ | ||
| remote/node_modules/ |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,34 @@ | ||||||
| import federation from '@originjs/vite-plugin-federation'; | ||||||
| import { execFileSync } from 'node:child_process'; | ||||||
| import path from 'node:path'; | ||||||
| import { fileURLToPath } from 'node:url'; | ||||||
| import { build } from 'vite'; | ||||||
|
|
||||||
| const fixture = path.dirname(fileURLToPath(import.meta.url)); | ||||||
| const name = process.argv[2]; | ||||||
| if (!name) { | ||||||
| // The federation plugin keeps its Rollup file references in module-level state. | ||||||
| for (const target of ['host', 'remote']) { | ||||||
| execFileSync(process.execPath, [fileURLToPath(import.meta.url), target], { stdio: 'inherit' }); | ||||||
| } | ||||||
| } else { | ||||||
| const root = path.join(fixture, name); | ||||||
| const remote = name === 'remote'; | ||||||
| await build({ | ||||||
| configFile: false, | ||||||
| root, | ||||||
| base: name === 'host' ? '/' : `/${name}/`, | ||||||
| build: { | ||||||
| target: 'esnext', | ||||||
| outDir: path.join(fixture, 'build', name === 'host' ? '.' : name), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The host build writes to Prompt for AI agents
Suggested change
|
||||||
| emptyOutDir: true, | ||||||
| rollupOptions: { input: path.join(root, 'index.html') }, | ||||||
| }, | ||||||
| plugins: [ | ||||||
| federation({ | ||||||
| name, | ||||||
| ...(remote ? { exposes: { './mount': path.join(root, 'mount.jsx') } } : { remotes: { fixture: '' } }), | ||||||
| }), | ||||||
| ], | ||||||
| }); | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| <div id="root"></div> | ||
| <script type="module" src="./main.js"></script> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import React from 'react'; | ||
| import { | ||
| __federation_method_getRemote as getRemote, | ||
| __federation_method_setRemote as setRemote, | ||
| } from 'virtual:__federation__'; | ||
|
|
||
| async function verify() { | ||
| setRemote('fixture', { format: 'esm', from: 'vite', url: '/remote/assets/remoteEntry.js' }); | ||
| const remote = await getRemote('fixture', './mount'); | ||
| if (!React.version.startsWith('17.') || !remote.reactVersion.startsWith('19.')) { | ||
| throw Error('Expected a React 17 host and an independent React 19 remote'); | ||
| } | ||
| let listener; | ||
| const element = document.getElementById('root'); | ||
| const cleanup = remote.mount(element, { | ||
| contractVersion: 1, | ||
| slot: 'nav.page', | ||
| area: 'app', | ||
| basePath: '/fixture', | ||
| theme: { id: 'light', colors: { textBrand: '#123456' }, styles: {} }, | ||
| subscribeTheme(cb) { | ||
| listener = cb; | ||
| return () => { | ||
| listener = undefined; | ||
| }; | ||
| }, | ||
| navigate() {}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Custom agent: Enforce Pragmatic Test Coverage This fixture passes a no-op Prompt for AI agents |
||
| }); | ||
| const label = element.firstElementChild; | ||
| if (label.textContent !== 'light' || getComputedStyle(label).color !== 'rgb(18, 52, 86)') | ||
| throw Error('Initial theme mismatch'); | ||
| listener({ id: 'themeV2Dark', colors: { textBrand: '#abcdef' }, styles: {} }); | ||
| if ( | ||
| label !== element.firstElementChild || | ||
| label.textContent !== 'themeV2Dark' || | ||
| getComputedStyle(label).color !== 'rgb(171, 205, 239)' | ||
| ) | ||
| throw Error('Live switch failed'); | ||
| cleanup(); | ||
| if (listener || element.childElementCount) throw Error('Cleanup failed'); | ||
| document.body.dataset.fixture = 'passed'; | ||
| } | ||
| verify().catch((error) => { | ||
| document.body.textContent = String(error); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <main></main> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import React, { useState } from 'react'; | ||
| import { flushSync } from 'react-dom'; | ||
| import { createRoot } from 'react-dom/client'; | ||
|
|
||
| export const reactVersion = React.version; | ||
|
|
||
| export function mount(element, props) { | ||
| if ( | ||
| props.contractVersion !== 1 || | ||
| props.slot !== 'nav.page' || | ||
| props.area !== 'app' || | ||
| props.basePath !== '/fixture' | ||
| ) { | ||
| throw Error('Expected the app page mount context'); | ||
| } | ||
| const root = createRoot(element); | ||
| function Label() { | ||
| const [theme, setTheme] = useState(props.theme); | ||
| React.useLayoutEffect(() => props.subscribeTheme((value) => flushSync(() => setTheme(value))), []); | ||
| return <span style={{ color: theme.colors.textBrand }}>{theme.id}</span>; | ||
| } | ||
| flushSync(() => root.render(<Label />)); | ||
| return () => root.unmount(); | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "name": "datahub-mfe-test-remote", | ||
| "private": true, | ||
| "dependencies": { | ||
| "react": "19.2.4", | ||
| "react-dom": "19.2.4" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| """Serve both production builds on one origin and check the browser result.""" | ||
| import functools | ||
| import http.server | ||
| import os | ||
| from pathlib import Path | ||
| import subprocess | ||
| import threading | ||
|
|
||
| root = Path(__file__).resolve().parent / "build" | ||
| handler = functools.partial(http.server.SimpleHTTPRequestHandler, directory=root) | ||
| with http.server.ThreadingHTTPServer(("127.0.0.1", 0), handler) as server: | ||
| threading.Thread(target=server.serve_forever, daemon=True).start() | ||
| page = subprocess.check_output([ | ||
| os.environ.get("CHROME_BIN", "google-chrome"), "--headless", "--no-sandbox", | ||
| "--disable-dev-shm-usage", "--dump-dom", "--virtual-time-budget=15000", | ||
| f"http://127.0.0.1:{server.server_port}/", | ||
| ], timeout=60, text=True) | ||
| if 'data-fixture="passed"' not in page: | ||
| raise SystemExit(page) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: This job does not exercise
src/app/mfeframework, even though the path filter runs it on changes there. The fixture's mount props are hand-written, so changes to the host contract can pass here. Either drive the real loader/container in this check or drop the path filter entry to avoid implying coverage.Prompt for AI agents