@appshell/react 0.2.2 → 0.3.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +5 -5
- package/__tests__/{FederatedComponent.spec.tsx → AppshellComponent.spec.tsx} +6 -6
- package/__tests__/ReactHost.spec.tsx +5 -5
- package/__tests__/__snapshots__/{FederatedComponent.spec.tsx.snap → AppshellComponent.spec.tsx.snap} +1 -1
- package/__tests__/__snapshots__/LoadingError.spec.tsx.snap +2 -2
- package/dist/main.js +1 -1
- package/dist/types/loader/src/{loadFederatedComponent.d.ts → loadAppshellComponent.d.ts} +1 -1
- package/dist/types/loader/src/loadAppshellComponent.d.ts.map +1 -0
- package/dist/types/react/src/components/AppshellComponent.d.ts +30 -0
- package/dist/types/react/src/components/AppshellComponent.d.ts.map +1 -0
- package/dist/types/react/src/index.d.ts +1 -1
- package/dist/types/react/src/index.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/components/{FederatedComponent.tsx → AppshellComponent.tsx} +12 -6
- package/src/components/LoadingError.tsx +1 -1
- package/src/components/ReactHost.tsx +2 -2
- package/src/index.ts +1 -1
- package/dist/types/loader/src/loadFederatedComponent.d.ts.map +0 -1
- package/dist/types/react/src/components/FederatedComponent.d.ts +0 -20
- package/dist/types/react/src/components/FederatedComponent.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.3.1-alpha.0](https://github.com/navaris/appshell/compare/@appshell/react@0.3.0...@appshell/react@0.3.1-alpha.0) (2024-08-31)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* bump pipeline ([8bb63bc](https://github.com/navaris/appshell/commit/8bb63bcae1928c01bb6bc853d88010939e686af5))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [0.3.0](https://github.com/navaris/appshell/compare/@appshell/react@0.2.2...@appshell/react@0.3.0) (2024-01-25)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* AppshellComponent impl ([2b82621](https://github.com/navaris/appshell/commit/2b82621c13302f790a8e1c457f9a82f39903fc1f))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [0.2.2](https://github.com/navaris/appshell/compare/@appshell/react@0.2.1...@appshell/react@0.2.2) (2024-01-04)
|
|
7
29
|
|
|
8
30
|
|
package/README.md
CHANGED
|
@@ -35,17 +35,17 @@ or
|
|
|
35
35
|
pnpm add -D @appshell/react
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
##
|
|
38
|
+
## AppshellComponent
|
|
39
39
|
|
|
40
|
-
React component that dynamically loads
|
|
40
|
+
React component that dynamically loads Appshell components.
|
|
41
41
|
|
|
42
42
|
```tsx
|
|
43
|
-
import {
|
|
43
|
+
import { AppshellComponent, ManifestProvider } from '@appshell/react';
|
|
44
44
|
|
|
45
45
|
<App>
|
|
46
46
|
<ManifestProvider manifest={manifest}>
|
|
47
|
-
<
|
|
48
|
-
<
|
|
47
|
+
<AppshellComponent remote="PingModule/Ping">
|
|
48
|
+
<AppshellComponent remote="PongModule/Pong">
|
|
49
49
|
</ManifestProvider>
|
|
50
50
|
</App>
|
|
51
51
|
```
|
|
@@ -3,7 +3,7 @@ import * as remoteLoader from '@appshell/loader';
|
|
|
3
3
|
import '@testing-library/jest-dom';
|
|
4
4
|
import { act, render, screen } from '@testing-library/react';
|
|
5
5
|
import React from 'react';
|
|
6
|
-
import
|
|
6
|
+
import AppshellComponent from '../src/components/AppshellComponent';
|
|
7
7
|
import * as useGlobalConfig from '../src/hooks/useGlobalConfig';
|
|
8
8
|
import manifest from './fixtures/Manifest';
|
|
9
9
|
import TestComponent from './fixtures/TestComponent';
|
|
@@ -13,13 +13,13 @@ jest.mock('../src/hooks/useGlobalConfig');
|
|
|
13
13
|
|
|
14
14
|
const TestFallback = () => <div>loading...</div>;
|
|
15
15
|
|
|
16
|
-
describe('
|
|
16
|
+
describe('AppshellComponent', () => {
|
|
17
17
|
it('should match snapshot', async () => {
|
|
18
18
|
jest.spyOn(useGlobalConfig, 'default').mockReturnValue(config);
|
|
19
19
|
jest.spyOn(remoteLoader, 'default').mockReturnValueOnce(async () => [TestComponent, manifest]);
|
|
20
20
|
|
|
21
21
|
const { container, findByText } = await act(() =>
|
|
22
|
-
render(<
|
|
22
|
+
render(<AppshellComponent remote="TestModule/TestComponent" />),
|
|
23
23
|
);
|
|
24
24
|
const view = await findByText(/test component/i);
|
|
25
25
|
|
|
@@ -32,7 +32,7 @@ describe('FederatedComponent', () => {
|
|
|
32
32
|
jest.spyOn(remoteLoader, 'default').mockReturnValueOnce(() => [null, null]);
|
|
33
33
|
|
|
34
34
|
await act(() =>
|
|
35
|
-
render(<
|
|
35
|
+
render(<AppshellComponent remote="TestModule/TestComponent" fallback={<TestFallback />} />),
|
|
36
36
|
);
|
|
37
37
|
|
|
38
38
|
expect(screen.getByText(/loading/i)).toBeInTheDocument();
|
|
@@ -45,9 +45,9 @@ describe('FederatedComponent', () => {
|
|
|
45
45
|
.mockImplementationOnce(() => new Error('Failed to get resource'));
|
|
46
46
|
|
|
47
47
|
await act(() =>
|
|
48
|
-
render(<
|
|
48
|
+
render(<AppshellComponent remote="TestModule/TestComponent" fallback={<TestFallback />} />),
|
|
49
49
|
);
|
|
50
50
|
|
|
51
|
-
expect(screen.getByText(/Error loading
|
|
51
|
+
expect(screen.getByText(/Error loading Appshell component/i)).toBeInTheDocument();
|
|
52
52
|
});
|
|
53
53
|
});
|
|
@@ -3,7 +3,7 @@ import '@testing-library/jest-dom';
|
|
|
3
3
|
import { act, render, screen } from '@testing-library/react';
|
|
4
4
|
import fetch, { enableFetchMocks } from 'jest-fetch-mock';
|
|
5
5
|
import React from 'react';
|
|
6
|
-
import * as
|
|
6
|
+
import * as AppshellComponent from '../src/components/AppshellComponent';
|
|
7
7
|
import ReactHost from '../src/components/ReactHost';
|
|
8
8
|
|
|
9
9
|
enableFetchMocks();
|
|
@@ -17,7 +17,7 @@ jest.mock('@appshell/core', () => ({
|
|
|
17
17
|
},
|
|
18
18
|
}));
|
|
19
19
|
|
|
20
|
-
jest.mock('../src/components/
|
|
20
|
+
jest.mock('../src/components/AppshellComponent', () => ({
|
|
21
21
|
__esModule: true,
|
|
22
22
|
default: () => <div>test component</div>,
|
|
23
23
|
}));
|
|
@@ -68,16 +68,16 @@ describe('RenderHost', () => {
|
|
|
68
68
|
expect(screen.getByText(/test component/i)).toBeInTheDocument();
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
it('should pass props to
|
|
71
|
+
it('should pass props to Appshell component when available', async () => {
|
|
72
72
|
mockUseState({ config: 'foo' });
|
|
73
|
-
const
|
|
73
|
+
const appshellComponentSpy = jest.spyOn(AppshellComponent, 'default');
|
|
74
74
|
await act(() =>
|
|
75
75
|
render(<ReactHost configUrl={configUrl} remote={remote} foo="bar" fallback="Loading" />),
|
|
76
76
|
);
|
|
77
77
|
|
|
78
78
|
expect(screen.getByText(/test component/i)).toBeInTheDocument();
|
|
79
79
|
|
|
80
|
-
expect(
|
|
80
|
+
expect(appshellComponentSpy).toHaveBeenCalledWith(
|
|
81
81
|
{ fallback: 'Loading', foo: 'bar', remote: 'TestModule/TestComponent' },
|
|
82
82
|
{},
|
|
83
83
|
);
|
|
@@ -9,7 +9,7 @@ exports[`LoadingError should match snapshot 1`] = `
|
|
|
9
9
|
style="border: 3px solid red;"
|
|
10
10
|
>
|
|
11
11
|
<h5>
|
|
12
|
-
Error loading
|
|
12
|
+
Error loading Appshell component 'TestModule/TestComponent.'
|
|
13
13
|
</h5>
|
|
14
14
|
<span
|
|
15
15
|
style="font-size: 1rem;"
|
|
@@ -24,7 +24,7 @@ exports[`LoadingError should match snapshot 1`] = `
|
|
|
24
24
|
style="border: 3px solid red;"
|
|
25
25
|
>
|
|
26
26
|
<h5>
|
|
27
|
-
Error loading
|
|
27
|
+
Error loading Appshell component 'TestModule/TestComponent.'
|
|
28
28
|
</h5>
|
|
29
29
|
<span
|
|
30
30
|
style="font-size: 1rem;"
|
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("react"));else if("function"==typeof define&&define.amd)define(["react"],t);else{var r="object"==typeof exports?t(require("react")):t(e.react);for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(self,(e=>(()=>{"use strict";var t={156:t=>{t.exports=e}},r={};function o(e){var n=r[e];if(void 0!==n)return n.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,o),a.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{o.S={};var e={},t={};o.I=(r,n)=>{n||(n=[]);var a=t[r];if(a||(a=t[r]={}),!(n.indexOf(a)>=0)){if(n.push(a),e[r])return e[r];o.o(o.S,r)||(o.S[r]={}),o.S[r];var
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("react"));else if("function"==typeof define&&define.amd)define(["react"],t);else{var r="object"==typeof exports?t(require("react")):t(e.react);for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(self,(e=>(()=>{"use strict";var t={156:t=>{t.exports=e}},r={};function o(e){var n=r[e];if(void 0!==n)return n.exports;var a=r[e]={exports:{}};return t[e](a,a.exports,o),a.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{o.S={};var e={},t={};o.I=(r,n)=>{n||(n=[]);var a=t[r];if(a||(a=t[r]={}),!(n.indexOf(a)>=0)){if(n.push(a),e[r])return e[r];o.o(o.S,r)||(o.S[r]={}),o.S[r];var s=[];return e[r]=s.length?Promise.all(s).then((()=>e[r]=1)):1}}})();var n={};return(()=>{o.r(n),o.d(n,{AppshellComponent:()=>v,FederatedComponent:()=>y,GlobalConfigProvider:()=>u,ManifestProvider:()=>l,MetadataProvider:()=>x,ReactHost:()=>b,jsonResource:()=>C,useGlobalConfig:()=>p,useManifest:()=>S,useMetadata:()=>j});const e=new Set,t=new Set,r=new Map;var a=o(156),s=o.n(a);const c=(0,a.createContext)({remotes:{},modules:{},environment:{}}),l=({manifest:e,children:t})=>s().createElement(c.Provider,{value:e},t),i=(c.Consumer,c),d=(0,a.createContext)({index:{}}),u=({config:e,children:t})=>s().createElement(d.Provider,{value:e},t),f=(d.Consumer,d),p=()=>s().useContext(f),m=({remote:e,reason:t})=>s().createElement("div",{style:{border:"3px solid red"}},s().createElement("h5",null,`Error loading Appshell component '${e}.'`),s().createElement("span",{style:{fontSize:"1rem"}},t)),h=({remote:n,fallback:c,...i})=>{const d=p(),[u,f]=(0,a.useState)();return(0,a.useEffect)((()=>{let a=!1;const c=(n=>async a=>{let s;const c=n.index[a];if(!c)throw new Error(`Remote resource not found in registry. Expected: ${a}`);try{const l=await(async e=>{if(r.has(e))return r.get(e);r.set(e,void 0);const t=await fetch(e);if(t.ok)return t.json();const o=await t.text();throw new Error(`Failed to get manifest from ${e}. ${o}`)})(c);if(l){r.set(c,l);const i=l.remotes[a],d=l.environment[i.scope]||{},u=n.overrides?.environment&&n.overrides?.environment[i.scope]||{};if(window[`__appshell_env__${i.scope}`]={...d,...u},t.has(i.remoteEntryUrl)||await(async t=>{const r=document.createElement("script");return new Promise(((o,n)=>{e.has(t)?o(!1):(e.add(t),r.src=t,r.type="text/javascript",r.async=!0,r.onload=()=>{console.debug(`Remote entry fetched from '${t}'.`),o(!0)},r.onerror=()=>{const e=`Failed to fetch remote entry from '${t}'.`;console.error(e),n(e)},document.head.appendChild(r))})).finally((()=>{document.head.contains(r)&&document.head.removeChild(r)}))})(i.remoteEntryUrl))return t.add(i.remoteEntryUrl),s=await(async(e,t,r="default")=>{console.debug(`loading Appshell component: { scope: ${e}, module: ${t}, shareScope: ${r} }`),await o.I(r);const n=window[e];if(!n)throw new Error(`Failed to find module container ${e}`);await n.init(o.S[r]);const a=await n.get(t);if(!a)throw new Error(`Invalid factory produced by container for module ${t}.`);const s=a();return console.debug(`Appshell component loaded: { scope: ${e}, module: ${t}, shareScope: ${r} }`),s.default})(i.scope,i.module,i.shareScope),[s,l]}return[null,null]}catch(e){throw new Error(`Failed to load component '${a}'. ${e?.toString()}`)}})(d);return a||async function(){try{a=!0,f(void 0);const[e,t]=await c(n);if(!e)return;a=!1,f(s().createElement(l,{manifest:t},s().createElement(e,i)))}catch(e){f(s().createElement(m,{remote:n,reason:`${e}`}))}}(),()=>{a=!1}}),[n,d,...Object.values(i)]),console.debug(`rendering AppshellComponent[${n}], loading=${!u}`),s().createElement(s().Fragment,null,u||c)};h.defaultProps={fallback:void 0};const v=h,y=h;function w(){return w=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)({}).hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},w.apply(null,arguments)}const g=({configUrl:e,remote:t,fallback:r,...o})=>{const[n,c]=s().useState();return(0,a.useEffect)((()=>{n||(async()=>{const t=await fetch(e);if(t.ok){const e=await t.json();c(e)}else c({index:{}})})()}),[n,e]),n?s().createElement(u,{config:n},s().createElement(v,w({remote:t,fallback:r},o))):null};g.defaultProps={fallback:void 0};const b=g,E=(0,a.createContext)({}),x=({metata:e,children:t})=>s().createElement(E.Provider,{value:e},t),$=(E.Consumer,E),S=()=>s().useContext(i),j=()=>s().useContext($),C=e=>{let t,r="pending";const o=fetch(e,{headers:{"Content-Type":"application/json",Accept:"application/json"}}).then((e=>{if(e.ok)return e.json().then((e=>{r="success",t=e}));r="error",t=new Error(`${e.status} ${e.statusText} ${e.url}`)}));return{read(){if("pending"===r)throw o;if("error"===r)throw t;if("success"===r)return t}}}})(),n})()));
|
|
@@ -11,4 +11,4 @@ declare global {
|
|
|
11
11
|
}
|
|
12
12
|
declare const _default: <TComponent>(scope: string, module: string, shareScope?: string) => Promise<TComponent>;
|
|
13
13
|
export default _default;
|
|
14
|
-
//# sourceMappingURL=
|
|
14
|
+
//# sourceMappingURL=loadAppshellComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadAppshellComponent.d.ts","sourceRoot":"","sources":["../../../../../loader/src/loadAppshellComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,OAAO,CAAC,MAAM,CAAC;IACb,SAAS,wBAAwB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7D,MAAM,wBAAwB,EAAE;QAAE,OAAO,EAAE,UAAU,CAAA;KAAE,CAAC;IACxD,UAAU,MAAM;QACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QACvB,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;KACtD;CACF;4CAIwC,MAAM,UAAU,MAAM;AAA/D,wBAgCE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AppshellIndex } from '@appshell/config';
|
|
2
|
+
import React, { ReactElement, ReactNode } from 'react';
|
|
3
|
+
export type ExtendedProps = Record<string, unknown>;
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
__appshell_index__: AppshellIndex;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export type AppshellComponentProps<TProps extends ExtendedProps = ExtendedProps> = {
|
|
10
|
+
remote: string;
|
|
11
|
+
fallback?: ReactNode;
|
|
12
|
+
} & TProps;
|
|
13
|
+
declare const AppshellComponent: {
|
|
14
|
+
<TProps extends ExtendedProps>({ remote, fallback, ...rest }: AppshellComponentProps<TProps>): React.ReactElement<TProps, string | React.JSXElementConstructor<any>>;
|
|
15
|
+
defaultProps: {
|
|
16
|
+
fallback: undefined;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export default AppshellComponent;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated This component is deprecated and will be removed in future versions.
|
|
22
|
+
* Please use AppshellComponent instead.
|
|
23
|
+
*/
|
|
24
|
+
export declare const FederatedComponent: {
|
|
25
|
+
<TProps extends ExtendedProps>({ remote, fallback, ...rest }: AppshellComponentProps<TProps>): React.ReactElement<TProps, string | React.JSXElementConstructor<any>>;
|
|
26
|
+
defaultProps: {
|
|
27
|
+
fallback: undefined;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=AppshellComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppshellComponent.d.ts","sourceRoot":"","sources":["../../../../../src/components/AppshellComponent.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,KAAK,EAAE,EAAiB,YAAY,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAK3F,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,kBAAkB,EAAE,aAAa,CAAC;KACnC;CACF;AAED,MAAM,MAAM,sBAAsB,CAAC,MAAM,SAAS,aAAa,GAAG,aAAa,IAAI;IACjF,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB,GAAG,MAAM,CAAC;AAEX,QAAA,MAAM,iBAAiB;;;;;CA6CtB,CAAC;AAMF,eAAe,iBAAiB,CAAC;AAEjC;;;GAGG;AACH,eAAO,MAAM,kBAAkB;;;;;CAAoB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { default as FederatedComponent } from './components/
|
|
1
|
+
export { default as AppshellComponent, FederatedComponent } from './components/AppshellComponent';
|
|
2
2
|
export { default as ReactHost } from './components/ReactHost';
|
|
3
3
|
export { GlobalConfigProvider } from './contexts/GlobalConfigContext';
|
|
4
4
|
export { ManifestProvider } from './contexts/ManifestContext';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAClG,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appshell/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1-alpha.0",
|
|
4
4
|
"description": "React utilities for building micro-frontends with Appshell and Module Federation",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/types/react/src/index.d.ts",
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"stats": "webpack --json > stats.json"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
|
-
"webpack",
|
|
22
21
|
"module federation",
|
|
23
22
|
"micro-frontends",
|
|
24
23
|
"appshell"
|
|
@@ -28,5 +27,5 @@
|
|
|
28
27
|
"react": "^18.2.0",
|
|
29
28
|
"react-dom": "^18.2.0"
|
|
30
29
|
},
|
|
31
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "a44ca542cf779c0cbbc527a02bc74d0a0619d0b9"
|
|
32
31
|
}
|
|
@@ -14,16 +14,16 @@ declare global {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
|
|
17
|
-
export type
|
|
17
|
+
export type AppshellComponentProps<TProps extends ExtendedProps = ExtendedProps> = {
|
|
18
18
|
remote: string;
|
|
19
19
|
fallback?: ReactNode;
|
|
20
20
|
} & TProps;
|
|
21
21
|
|
|
22
|
-
const
|
|
22
|
+
const AppshellComponent = <TProps extends ExtendedProps>({
|
|
23
23
|
remote,
|
|
24
24
|
fallback,
|
|
25
25
|
...rest
|
|
26
|
-
}:
|
|
26
|
+
}: AppshellComponentProps<TProps>): ReactElement<TProps> => {
|
|
27
27
|
const config = useGlobalConfig();
|
|
28
28
|
const [element, setElement] = useState<ReactElement>();
|
|
29
29
|
|
|
@@ -61,13 +61,19 @@ const FederatedComponent = <TProps extends ExtendedProps>({
|
|
|
61
61
|
}, [remote, config, ...Object.values(rest)]);
|
|
62
62
|
|
|
63
63
|
// eslint-disable-next-line no-console
|
|
64
|
-
console.debug(`rendering
|
|
64
|
+
console.debug(`rendering AppshellComponent[${remote}], loading=${!element}`);
|
|
65
65
|
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
66
66
|
return <>{element || fallback}</>;
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
AppshellComponent.defaultProps = {
|
|
70
70
|
fallback: undefined,
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
export default
|
|
73
|
+
export default AppshellComponent;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @deprecated This component is deprecated and will be removed in future versions.
|
|
77
|
+
* Please use AppshellComponent instead.
|
|
78
|
+
*/
|
|
79
|
+
export const FederatedComponent = AppshellComponent;
|
|
@@ -7,7 +7,7 @@ type ErrorProps = {
|
|
|
7
7
|
|
|
8
8
|
const LoadingError: FC<ErrorProps> = ({ remote, reason }) => (
|
|
9
9
|
<div style={{ border: '3px solid red' }}>
|
|
10
|
-
<h5>{`Error loading
|
|
10
|
+
<h5>{`Error loading Appshell component '${remote}.'`}</h5>
|
|
11
11
|
<span style={{ fontSize: '1rem' }}>{reason}</span>
|
|
12
12
|
</div>
|
|
13
13
|
);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { AppshellGlobalConfig } from 'packages/config/src/types';
|
|
3
3
|
import React, { FC, ReactNode, useEffect } from 'react';
|
|
4
4
|
import { GlobalConfigProvider } from '../contexts/GlobalConfigContext';
|
|
5
|
-
import
|
|
5
|
+
import AppshellComponent from './AppshellComponent';
|
|
6
6
|
|
|
7
7
|
const ReactHost: FC<{
|
|
8
8
|
configUrl: string;
|
|
@@ -35,7 +35,7 @@ const ReactHost: FC<{
|
|
|
35
35
|
|
|
36
36
|
return (
|
|
37
37
|
<GlobalConfigProvider config={config}>
|
|
38
|
-
<
|
|
38
|
+
<AppshellComponent remote={remote} fallback={fallback} {...rest} />
|
|
39
39
|
</GlobalConfigProvider>
|
|
40
40
|
);
|
|
41
41
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { default as FederatedComponent } from './components/
|
|
1
|
+
export { default as AppshellComponent, FederatedComponent } from './components/AppshellComponent';
|
|
2
2
|
export { default as ReactHost } from './components/ReactHost';
|
|
3
3
|
export { GlobalConfigProvider } from './contexts/GlobalConfigContext';
|
|
4
4
|
export { ManifestProvider } from './contexts/ManifestContext';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loadFederatedComponent.d.ts","sourceRoot":"","sources":["../../../../../loader/src/loadFederatedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,OAAO,CAAC,MAAM,CAAC;IACb,SAAS,wBAAwB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7D,MAAM,wBAAwB,EAAE;QAAE,OAAO,EAAE,UAAU,CAAA;KAAE,CAAC;IACxD,UAAU,MAAM;QACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QACvB,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;KACtD;CACF;4CAIwC,MAAM,UAAU,MAAM;AAA/D,wBAgCE"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { AppshellIndex } from '@appshell/config';
|
|
2
|
-
import React, { ReactElement, ReactNode } from 'react';
|
|
3
|
-
export type ExtendedProps = Record<string, unknown>;
|
|
4
|
-
declare global {
|
|
5
|
-
interface Window {
|
|
6
|
-
__appshell_index__: AppshellIndex;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export type FederatedComponentProps<TProps extends ExtendedProps = ExtendedProps> = {
|
|
10
|
-
remote: string;
|
|
11
|
-
fallback?: ReactNode;
|
|
12
|
-
} & TProps;
|
|
13
|
-
declare const FederatedComponent: {
|
|
14
|
-
<TProps extends ExtendedProps>({ remote, fallback, ...rest }: FederatedComponentProps<TProps>): React.ReactElement<TProps, string | React.JSXElementConstructor<any>>;
|
|
15
|
-
defaultProps: {
|
|
16
|
-
fallback: undefined;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export default FederatedComponent;
|
|
20
|
-
//# sourceMappingURL=FederatedComponent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FederatedComponent.d.ts","sourceRoot":"","sources":["../../../../../src/components/FederatedComponent.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,KAAK,EAAE,EAAiB,YAAY,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAK3F,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,kBAAkB,EAAE,aAAa,CAAC;KACnC;CACF;AAED,MAAM,MAAM,uBAAuB,CAAC,MAAM,SAAS,aAAa,GAAG,aAAa,IAAI;IAClF,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB,GAAG,MAAM,CAAC;AAEX,QAAA,MAAM,kBAAkB;;;;;CA6CvB,CAAC;AAMF,eAAe,kBAAkB,CAAC"}
|