@servicetitan/web-components 40.2.2 → 40.4.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.
Files changed (104) hide show
  1. package/dist/common.d.ts +22 -6
  2. package/dist/common.d.ts.map +1 -1
  3. package/dist/common.js +7 -2
  4. package/dist/common.js.map +1 -1
  5. package/dist/globals.d.ts +9 -7
  6. package/dist/globals.d.ts.map +1 -1
  7. package/dist/globals.js +17 -6
  8. package/dist/globals.js.map +1 -1
  9. package/dist/loader.d.ts.map +1 -1
  10. package/dist/loader.js +26 -24
  11. package/dist/loader.js.map +1 -1
  12. package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.d.ts +3 -0
  13. package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.d.ts.map +1 -0
  14. package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.js +12 -0
  15. package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.js.map +1 -0
  16. package/dist/patches/kendo-scrollbar-width/index.d.ts +3 -0
  17. package/dist/patches/kendo-scrollbar-width/index.d.ts.map +1 -0
  18. package/dist/patches/kendo-scrollbar-width/index.js +4 -0
  19. package/dist/patches/kendo-scrollbar-width/index.js.map +1 -0
  20. package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.d.ts +2 -0
  21. package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.d.ts.map +1 -0
  22. package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.js +26 -0
  23. package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.js.map +1 -0
  24. package/dist/register.d.ts.map +1 -1
  25. package/dist/register.js +30 -7
  26. package/dist/register.js.map +1 -1
  27. package/dist/use-host-shared-dependencies.d.ts +7 -0
  28. package/dist/use-host-shared-dependencies.d.ts.map +1 -0
  29. package/dist/use-host-shared-dependencies.js +17 -0
  30. package/dist/use-host-shared-dependencies.js.map +1 -0
  31. package/dist/use-prefetch.d.ts +2 -3
  32. package/dist/use-prefetch.d.ts.map +1 -1
  33. package/dist/use-prefetch.js +18 -12
  34. package/dist/use-prefetch.js.map +1 -1
  35. package/dist/utils/get-bundle-info.d.ts +7 -5
  36. package/dist/utils/get-bundle-info.d.ts.map +1 -1
  37. package/dist/utils/get-bundle-info.js +5 -3
  38. package/dist/utils/get-bundle-info.js.map +1 -1
  39. package/dist/utils/get-mfe-has-compatible-launchdarkly-version.d.ts +6 -6
  40. package/dist/utils/get-mfe-has-compatible-launchdarkly-version.d.ts.map +1 -1
  41. package/dist/utils/get-mfe-has-compatible-launchdarkly-version.js +7 -7
  42. package/dist/utils/get-mfe-has-compatible-launchdarkly-version.js.map +1 -1
  43. package/dist/utils/validate-bundle-info.d.ts +5 -5
  44. package/dist/utils/validate-bundle-info.d.ts.map +1 -1
  45. package/dist/utils/validate-bundle-info.js +6 -5
  46. package/dist/utils/validate-bundle-info.js.map +1 -1
  47. package/dist/utils/web-component.d.ts +4 -4
  48. package/dist/utils/web-component.d.ts.map +1 -1
  49. package/dist/utils/web-component.js +27 -11
  50. package/dist/utils/web-component.js.map +1 -1
  51. package/package.json +18 -14
  52. package/src/common.ts +27 -6
  53. package/src/globals.ts +26 -8
  54. package/src/loader.tsx +32 -36
  55. package/src/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.ts +11 -0
  56. package/src/patches/kendo-scrollbar-width/index.ts +2 -0
  57. package/src/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.ts +27 -0
  58. package/src/register.tsx +35 -8
  59. package/src/use-host-shared-dependencies.ts +26 -0
  60. package/src/use-prefetch.ts +38 -40
  61. package/src/utils/get-bundle-info.ts +11 -8
  62. package/src/utils/get-mfe-has-compatible-launchdarkly-version.ts +7 -7
  63. package/src/utils/validate-bundle-info.ts +9 -8
  64. package/src/utils/web-component.tsx +39 -16
  65. package/dist/contexts/tests/mfe-data-context.test.d.ts +0 -2
  66. package/dist/contexts/tests/mfe-data-context.test.d.ts.map +0 -1
  67. package/dist/contexts/tests/mfe-data-context.test.js +0 -60
  68. package/dist/contexts/tests/mfe-data-context.test.js.map +0 -1
  69. package/dist/contexts/tests/mfe-metadata-context.test.d.ts +0 -2
  70. package/dist/contexts/tests/mfe-metadata-context.test.d.ts.map +0 -1
  71. package/dist/contexts/tests/mfe-metadata-context.test.js +0 -41
  72. package/dist/contexts/tests/mfe-metadata-context.test.js.map +0 -1
  73. package/src/__mocks__/expect-styles-in-dom.ts +0 -11
  74. package/src/__mocks__/index.ts +0 -3
  75. package/src/__mocks__/register-anvil2-harness.tsx +0 -49
  76. package/src/__mocks__/register-component.tsx +0 -20
  77. package/src/__mocks__/test-component.tsx +0 -41
  78. package/src/__tests__/common.test.ts +0 -204
  79. package/src/__tests__/delayed.test.tsx +0 -49
  80. package/src/__tests__/event-bus-types.test.ts +0 -620
  81. package/src/__tests__/event-bus.test.ts +0 -240
  82. package/src/__tests__/get-value-for-environment.test.ts +0 -95
  83. package/src/__tests__/globals.test.ts +0 -16
  84. package/src/__tests__/headless-loader.test.tsx +0 -123
  85. package/src/__tests__/history-manager.test.ts +0 -111
  86. package/src/__tests__/loader.test.tsx +0 -1178
  87. package/src/__tests__/register-anvil2-optional.test.tsx +0 -32
  88. package/src/__tests__/register-anvil2.test.tsx +0 -80
  89. package/src/__tests__/register-headless.test.tsx +0 -97
  90. package/src/__tests__/register-legacy-root.test.tsx +0 -38
  91. package/src/__tests__/register.test.tsx +0 -247
  92. package/src/__tests__/use-prefetch.test.tsx +0 -235
  93. package/src/contexts/tests/mfe-data-context.test.tsx +0 -64
  94. package/src/contexts/tests/mfe-metadata-context.test.tsx +0 -34
  95. package/src/css-injector/__tests__/mfe-style-registry.test.ts +0 -163
  96. package/src/css-injector/__tests__/with-css-injector.test.tsx +0 -128
  97. package/src/utils/__tests__/get-cached-metadata.test.ts +0 -94
  98. package/src/utils/__tests__/get-mfe-has-compatible-launchdarkly-version.test.ts +0 -54
  99. package/src/utils/__tests__/get-mfe-supports-rerendering.test.ts +0 -99
  100. package/src/utils/__tests__/get-mfe-supports-versioned-ld-client.test.ts +0 -38
  101. package/src/utils/__tests__/is-versioned-url.test.ts +0 -18
  102. package/src/utils/__tests__/load-scripts.test.ts +0 -171
  103. package/src/utils/__tests__/supports-prefetch.test.ts +0 -27
  104. package/src/utils/__tests__/ttl-cache.test.ts +0 -98
@@ -1,24 +1,32 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useOptionalDependencies } from '@servicetitan/react-ioc';
3
- import { Fragment, useMemo, useState } from 'react';
3
+ import { Fragment, useLayoutEffect, useMemo, useRef, useState } from 'react';
4
4
  import { HistoryManager } from '../history-manager';
5
+ import { setKendoScrollbarWidth } from '../patches/kendo-scrollbar-width';
5
6
  import { getElementName } from './get-element-name';
6
7
  export function webComponent(props) {
7
8
  var _bundleInfo_bundledWith;
8
- const { basename, bundleInfo, eventBus, exposedDependencies, ldService, logService } = props;
9
- const { WebComponent, resolvedBundleType, mfeSupportsRerendering, version } = bundleInfo;
9
+ const { basename, bundleInfo, eventBus, hostSharedDependencies, ldService, logService } = props;
10
+ const { WebComponent, resolvedBundleType, mfeSupportsRerendering, mfeMaybeUsesKendoGrid, version } = bundleInfo;
10
11
  const elementName = getElementName(bundleInfo);
11
- const exposedInstanceDependencies = ensureLDVersion(props.exposedInstanceDependencies, (_bundleInfo_bundledWith = bundleInfo.bundledWith) === null || _bundleInfo_bundledWith === void 0 ? void 0 : _bundleInfo_bundledWith['launchdarkly-js-client-sdk']);
12
+ const sharedInstanceDependencies = ensureLDVersion(props.sharedInstanceDependencies, (_bundleInfo_bundledWith = bundleInfo.bundledWith) === null || _bundleInfo_bundledWith === void 0 ? void 0 : _bundleInfo_bundledWith['launchdarkly-js-client-sdk']);
12
13
  return ({ LoadingFallback, ...innerProps })=>{
13
14
  const [isLoading, setIsLoading] = useState(true);
14
15
  const [historyManager] = useOptionalDependencies(HistoryManager);
16
+ const elementRef = useRef(null);
15
17
  const handleRef = (webComponent)=>{
18
+ elementRef.current = webComponent;
16
19
  webComponent === null || webComponent === void 0 ? void 0 : webComponent.provide({
17
20
  ldService,
18
21
  logService,
19
22
  historyManager,
20
- exposedDependencies,
21
- exposedInstanceDependencies,
23
+ sharedDependencies: hostSharedDependencies,
24
+ sharedInstanceDependencies,
25
+ /*
26
+ * Continue to pass the deprecated names for backwards compatibility,
27
+ * in case the Host has updated web-components, but the MFE has not
28
+ */ exposedDependencies: hostSharedDependencies,
29
+ exposedInstanceDependencies: sharedInstanceDependencies,
22
30
  eventBus,
23
31
  basename,
24
32
  onReady: ()=>{
@@ -36,6 +44,14 @@ export function webComponent(props) {
36
44
  * the web component will be re-mounted whenever the data changes.
37
45
  * This is only used as a fallback when the MFE's version is older.
38
46
  */ const key = mfeSupportsRerendering ? undefined : stringifiedData;
47
+ // Measure after the element is visible, since a hidden element has no scrollbar.
48
+ useLayoutEffect(()=>{
49
+ if (mfeMaybeUsesKendoGrid && !isLoading && elementRef.current) {
50
+ setKendoScrollbarWidth(elementRef.current, elementName);
51
+ }
52
+ }, [
53
+ isLoading
54
+ ]);
39
55
  const dataAttrs = useMemo(()=>composeDataAttributes(innerProps.data), [
40
56
  innerProps.data
41
57
  ]);
@@ -73,17 +89,17 @@ export function webComponent(props) {
73
89
  value
74
90
  ]));
75
91
  }
76
- function ensureLDVersion(exposedInstanceDependencies = {}, version) {
77
- var _exposedInstanceDependencies_launchDarkly;
78
- if (version && !((_exposedInstanceDependencies_launchDarkly = exposedInstanceDependencies.launchDarkly) === null || _exposedInstanceDependencies_launchDarkly === void 0 ? void 0 : _exposedInstanceDependencies_launchDarkly.ldService)) {
92
+ function ensureLDVersion(sharedInstanceDependencies = {}, version) {
93
+ var _sharedInstanceDependencies_launchDarkly;
94
+ if (version && !((_sharedInstanceDependencies_launchDarkly = sharedInstanceDependencies.launchDarkly) === null || _sharedInstanceDependencies_launchDarkly === void 0 ? void 0 : _sharedInstanceDependencies_launchDarkly.ldService)) {
79
95
  return {
80
- ...exposedInstanceDependencies,
96
+ ...sharedInstanceDependencies,
81
97
  launchDarkly: {
82
98
  version
83
99
  }
84
100
  };
85
101
  }
86
- return exposedInstanceDependencies;
102
+ return sharedInstanceDependencies;
87
103
  }
88
104
  function getStyleUrls({ urls }) {
89
105
  if (urls.css.length) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/web-component.tsx"],"sourcesContent":["import { type LDService } from '@servicetitan/launchdarkly-service';\nimport { Log } from '@servicetitan/log-service';\nimport { useOptionalDependencies } from '@servicetitan/react-ioc';\nimport { ExposedDependencies } from '@servicetitan/startup-utils';\nimport { Fragment, useMemo, useState } from 'react';\nimport { ExposedInstanceDependencies, IWebComponent } from '../common';\nimport { MFEContextData } from '../contexts/mfe-data-context';\nimport { EventBus } from '../event-bus';\nimport { HistoryManager } from '../history-manager';\nimport { LoaderDataProps } from '../loader';\nimport { BundleInfo } from './get-bundle-info';\nimport { getElementName } from './get-element-name';\n\ninterface WebComponentProps {\n basename?: string;\n bundleInfo: BundleInfo;\n eventBus: EventBus;\n exposedDependencies?: ExposedDependencies;\n exposedInstanceDependencies?: ExposedInstanceDependencies;\n ldService?: LDService;\n logService?: Log;\n}\n\nexport function webComponent(props: WebComponentProps) {\n const { basename, bundleInfo, eventBus, exposedDependencies, ldService, logService } = props;\n const { WebComponent, resolvedBundleType, mfeSupportsRerendering, version } = bundleInfo;\n const elementName = getElementName(bundleInfo);\n\n const exposedInstanceDependencies = ensureLDVersion(\n props.exposedInstanceDependencies,\n bundleInfo.bundledWith?.['launchdarkly-js-client-sdk']\n );\n\n return ({ LoadingFallback, ...innerProps }: LoaderDataProps) => {\n const [isLoading, setIsLoading] = useState(true);\n const [historyManager] = useOptionalDependencies(HistoryManager);\n\n const handleRef = (webComponent: IWebComponent | null) => {\n webComponent?.provide({\n ldService,\n logService,\n historyManager,\n exposedDependencies,\n exposedInstanceDependencies,\n eventBus,\n basename,\n onReady: () => {\n setIsLoading(false);\n },\n });\n };\n\n // Stringify data object so that it can be passed as a data-attribute\n const stringifiedData = useMemo(() => JSON.stringify(innerProps.data), [innerProps.data]);\n\n /*\n * Set key for rendering the web component so that if the data from the Host change,\n * and the MFE's version of startup doesn't support watching for data changes, then\n * the web component will be re-mounted whenever the data changes.\n * This is only used as a fallback when the MFE's version is older.\n */\n const key = mfeSupportsRerendering ? undefined : stringifiedData;\n const dataAttrs = useMemo(() => composeDataAttributes(innerProps.data), [innerProps.data]);\n const styleUrls = getStyleUrls(bundleInfo);\n\n return (\n <Fragment>\n {isLoading && <LoadingFallback />}\n <WebComponent\n key={key}\n ref={handleRef}\n class={innerProps.className}\n {...(styleUrls && { 'style-urls': styleUrls })}\n /*\n * Continue to spread data as separate data attributes for backwards compatibility,\n * in case the Host has updated web-components, but the MFE has not\n */\n {...dataAttrs}\n data-mfe-data={stringifiedData}\n data-mfe-name={elementName}\n {...(version && { 'data-mfe-version': version })}\n // @ts-expect-error style exists on HTMLElement\n style={\n isLoading || resolvedBundleType === 'headless'\n ? { display: 'none' }\n : undefined\n }\n />\n </Fragment>\n );\n };\n}\n\n/*\n * Convert camelCase data props to kebab-case data attributes, prepended with data-\n * Ex: fooBar -> data-foo-bar\n */\nfunction composeDataAttributes(data: MFEContextData<{}> | undefined = {}) {\n return Object.fromEntries(\n Object.entries(data).map(([key, value]) => [\n 'data-' + key.replace(/[A-Z]/g, letter => '-' + letter.toLowerCase()),\n value,\n ])\n );\n}\n\nfunction ensureLDVersion(\n exposedInstanceDependencies: ExposedInstanceDependencies = {},\n version?: string\n) {\n if (version && !exposedInstanceDependencies.launchDarkly?.ldService) {\n return { ...exposedInstanceDependencies, launchDarkly: { version } };\n }\n return exposedInstanceDependencies;\n}\n\nfunction getStyleUrls({ urls }: Pick<BundleInfo, 'urls'>) {\n if (urls.css.length) {\n return encodeURIComponent(JSON.stringify(urls.css));\n }\n}\n"],"names":["useOptionalDependencies","Fragment","useMemo","useState","HistoryManager","getElementName","webComponent","props","bundleInfo","basename","eventBus","exposedDependencies","ldService","logService","WebComponent","resolvedBundleType","mfeSupportsRerendering","version","elementName","exposedInstanceDependencies","ensureLDVersion","bundledWith","LoadingFallback","innerProps","isLoading","setIsLoading","historyManager","handleRef","provide","onReady","stringifiedData","JSON","stringify","data","key","undefined","dataAttrs","composeDataAttributes","styleUrls","getStyleUrls","ref","class","className","data-mfe-data","data-mfe-name","style","display","Object","fromEntries","entries","map","value","replace","letter","toLowerCase","launchDarkly","urls","css","length","encodeURIComponent"],"mappings":";AAEA,SAASA,uBAAuB,QAAQ,0BAA0B;AAElE,SAASC,QAAQ,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAIpD,SAASC,cAAc,QAAQ,qBAAqB;AAGpD,SAASC,cAAc,QAAQ,qBAAqB;AAYpD,OAAO,SAASC,aAAaC,KAAwB;QAO7CC;IANJ,MAAM,EAAEC,QAAQ,EAAED,UAAU,EAAEE,QAAQ,EAAEC,mBAAmB,EAAEC,SAAS,EAAEC,UAAU,EAAE,GAAGN;IACvF,MAAM,EAAEO,YAAY,EAAEC,kBAAkB,EAAEC,sBAAsB,EAAEC,OAAO,EAAE,GAAGT;IAC9E,MAAMU,cAAcb,eAAeG;IAEnC,MAAMW,8BAA8BC,gBAChCb,MAAMY,2BAA2B,GACjCX,0BAAAA,WAAWa,WAAW,cAAtBb,8CAAAA,uBAAwB,CAAC,6BAA6B;IAG1D,OAAO,CAAC,EAAEc,eAAe,EAAE,GAAGC,YAA6B;QACvD,MAAM,CAACC,WAAWC,aAAa,GAAGtB,SAAS;QAC3C,MAAM,CAACuB,eAAe,GAAG1B,wBAAwBI;QAEjD,MAAMuB,YAAY,CAACrB;YACfA,yBAAAA,mCAAAA,aAAcsB,OAAO,CAAC;gBAClBhB;gBACAC;gBACAa;gBACAf;gBACAQ;gBACAT;gBACAD;gBACAoB,SAAS;oBACLJ,aAAa;gBACjB;YACJ;QACJ;QAEA,qEAAqE;QACrE,MAAMK,kBAAkB5B,QAAQ,IAAM6B,KAAKC,SAAS,CAACT,WAAWU,IAAI,GAAG;YAACV,WAAWU,IAAI;SAAC;QAExF;;;;;SAKC,GACD,MAAMC,MAAMlB,yBAAyBmB,YAAYL;QACjD,MAAMM,YAAYlC,QAAQ,IAAMmC,sBAAsBd,WAAWU,IAAI,GAAG;YAACV,WAAWU,IAAI;SAAC;QACzF,MAAMK,YAAYC,aAAa/B;QAE/B,qBACI,MAACP;;gBACIuB,2BAAa,KAACF;8BACf,KAACR;oBAEG0B,KAAKb;oBACLc,OAAOlB,WAAWmB,SAAS;oBAC1B,GAAIJ,aAAa;wBAAE,cAAcA;oBAAU,CAAC;oBAK5C,GAAGF,SAAS;oBACbO,iBAAeb;oBACfc,iBAAe1B;oBACd,GAAID,WAAW;wBAAE,oBAAoBA;oBAAQ,CAAC;oBAC/C,+CAA+C;oBAC/C4B,OACIrB,aAAaT,uBAAuB,aAC9B;wBAAE+B,SAAS;oBAAO,IAClBX;mBAhBLD;;;IAqBrB;AACJ;AAEA;;;CAGC,GACD,SAASG,sBAAsBJ,OAAuC,CAAC,CAAC;IACpE,OAAOc,OAAOC,WAAW,CACrBD,OAAOE,OAAO,CAAChB,MAAMiB,GAAG,CAAC,CAAC,CAAChB,KAAKiB,MAAM,GAAK;YACvC,UAAUjB,IAAIkB,OAAO,CAAC,UAAUC,CAAAA,SAAU,MAAMA,OAAOC,WAAW;YAClEH;SACH;AAET;AAEA,SAAS/B,gBACLD,8BAA2D,CAAC,CAAC,EAC7DF,OAAgB;QAEAE;IAAhB,IAAIF,WAAW,GAACE,4CAAAA,4BAA4BoC,YAAY,cAAxCpC,gEAAAA,0CAA0CP,SAAS,GAAE;QACjE,OAAO;YAAE,GAAGO,2BAA2B;YAAEoC,cAAc;gBAAEtC;YAAQ;QAAE;IACvE;IACA,OAAOE;AACX;AAEA,SAASoB,aAAa,EAAEiB,IAAI,EAA4B;IACpD,IAAIA,KAAKC,GAAG,CAACC,MAAM,EAAE;QACjB,OAAOC,mBAAmB5B,KAAKC,SAAS,CAACwB,KAAKC,GAAG;IACrD;AACJ"}
1
+ {"version":3,"sources":["../../src/utils/web-component.tsx"],"sourcesContent":["import { type LDService } from '@servicetitan/launchdarkly-service';\nimport { Log } from '@servicetitan/log-service';\nimport { useOptionalDependencies } from '@servicetitan/react-ioc';\nimport { SharedDependencies } from '@servicetitan/startup-utils';\nimport { Fragment, useLayoutEffect, useMemo, useRef, useState } from 'react';\nimport { IWebComponent, SharedInstanceDependencies } from '../common';\nimport { MFEContextData } from '../contexts/mfe-data-context';\nimport { EventBus } from '../event-bus';\nimport { HistoryManager } from '../history-manager';\nimport { LoaderDataProps } from '../loader';\nimport { setKendoScrollbarWidth } from '../patches/kendo-scrollbar-width';\nimport { BundleInfo } from './get-bundle-info';\nimport { getElementName } from './get-element-name';\n\ninterface WebComponentProps {\n basename?: string;\n bundleInfo: BundleInfo;\n eventBus: EventBus;\n hostSharedDependencies?: SharedDependencies;\n sharedInstanceDependencies?: SharedInstanceDependencies;\n ldService?: LDService;\n logService?: Log;\n}\n\nexport function webComponent(props: WebComponentProps) {\n const { basename, bundleInfo, eventBus, hostSharedDependencies, ldService, logService } = props;\n const {\n WebComponent,\n resolvedBundleType,\n mfeSupportsRerendering,\n mfeMaybeUsesKendoGrid,\n version,\n } = bundleInfo;\n const elementName = getElementName(bundleInfo);\n\n const sharedInstanceDependencies = ensureLDVersion(\n props.sharedInstanceDependencies,\n bundleInfo.bundledWith?.['launchdarkly-js-client-sdk']\n );\n\n return ({ LoadingFallback, ...innerProps }: LoaderDataProps) => {\n const [isLoading, setIsLoading] = useState(true);\n const [historyManager] = useOptionalDependencies(HistoryManager);\n const elementRef = useRef<(IWebComponent & HTMLElement) | null>(null);\n\n const handleRef = (webComponent: (IWebComponent & HTMLElement) | null) => {\n elementRef.current = webComponent;\n webComponent?.provide({\n ldService,\n logService,\n historyManager,\n sharedDependencies: hostSharedDependencies,\n sharedInstanceDependencies,\n /*\n * Continue to pass the deprecated names for backwards compatibility,\n * in case the Host has updated web-components, but the MFE has not\n */\n exposedDependencies: hostSharedDependencies,\n exposedInstanceDependencies: sharedInstanceDependencies,\n eventBus,\n basename,\n onReady: () => {\n setIsLoading(false);\n },\n });\n };\n\n // Stringify data object so that it can be passed as a data-attribute\n const stringifiedData = useMemo(() => JSON.stringify(innerProps.data), [innerProps.data]);\n\n /*\n * Set key for rendering the web component so that if the data from the Host change,\n * and the MFE's version of startup doesn't support watching for data changes, then\n * the web component will be re-mounted whenever the data changes.\n * This is only used as a fallback when the MFE's version is older.\n */\n const key = mfeSupportsRerendering ? undefined : stringifiedData;\n\n // Measure after the element is visible, since a hidden element has no scrollbar.\n useLayoutEffect(() => {\n if (mfeMaybeUsesKendoGrid && !isLoading && elementRef.current) {\n setKendoScrollbarWidth(elementRef.current, elementName);\n }\n }, [isLoading]);\n\n const dataAttrs = useMemo(() => composeDataAttributes(innerProps.data), [innerProps.data]);\n const styleUrls = getStyleUrls(bundleInfo);\n\n return (\n <Fragment>\n {isLoading && <LoadingFallback />}\n <WebComponent\n key={key}\n ref={handleRef}\n class={innerProps.className}\n {...(styleUrls && { 'style-urls': styleUrls })}\n /*\n * Continue to spread data as separate data attributes for backwards compatibility,\n * in case the Host has updated web-components, but the MFE has not\n */\n {...dataAttrs}\n data-mfe-data={stringifiedData}\n data-mfe-name={elementName}\n {...(version && { 'data-mfe-version': version })}\n // @ts-expect-error style exists on HTMLElement\n style={\n isLoading || resolvedBundleType === 'headless'\n ? { display: 'none' }\n : undefined\n }\n />\n </Fragment>\n );\n };\n}\n\n/*\n * Convert camelCase data props to kebab-case data attributes, prepended with data-\n * Ex: fooBar -> data-foo-bar\n */\nfunction composeDataAttributes(data: MFEContextData<{}> | undefined = {}) {\n return Object.fromEntries(\n Object.entries(data).map(([key, value]) => [\n 'data-' + key.replace(/[A-Z]/g, letter => '-' + letter.toLowerCase()),\n value,\n ])\n );\n}\n\nfunction ensureLDVersion(\n sharedInstanceDependencies: SharedInstanceDependencies = {},\n version?: string\n) {\n if (version && !sharedInstanceDependencies.launchDarkly?.ldService) {\n return { ...sharedInstanceDependencies, launchDarkly: { version } };\n }\n return sharedInstanceDependencies;\n}\n\nfunction getStyleUrls({ urls }: Pick<BundleInfo, 'urls'>) {\n if (urls.css.length) {\n return encodeURIComponent(JSON.stringify(urls.css));\n }\n}\n"],"names":["useOptionalDependencies","Fragment","useLayoutEffect","useMemo","useRef","useState","HistoryManager","setKendoScrollbarWidth","getElementName","webComponent","props","bundleInfo","basename","eventBus","hostSharedDependencies","ldService","logService","WebComponent","resolvedBundleType","mfeSupportsRerendering","mfeMaybeUsesKendoGrid","version","elementName","sharedInstanceDependencies","ensureLDVersion","bundledWith","LoadingFallback","innerProps","isLoading","setIsLoading","historyManager","elementRef","handleRef","current","provide","sharedDependencies","exposedDependencies","exposedInstanceDependencies","onReady","stringifiedData","JSON","stringify","data","key","undefined","dataAttrs","composeDataAttributes","styleUrls","getStyleUrls","ref","class","className","data-mfe-data","data-mfe-name","style","display","Object","fromEntries","entries","map","value","replace","letter","toLowerCase","launchDarkly","urls","css","length","encodeURIComponent"],"mappings":"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/web-components",
3
- "version": "40.2.2",
3
+ "version": "40.4.0",
4
4
  "description": "Framework to build, register, and load Microfrontends into host applications",
5
5
  "homepage": "https://docs.st.dev/docs/frontend/uikit/web-components",
6
6
  "repository": {
@@ -28,27 +28,31 @@
28
28
  "sideEffects": false,
29
29
  "files": [
30
30
  "dist",
31
- "src"
31
+ "src",
32
+ "!**/__tests__",
33
+ "!**/__mocks__",
34
+ "!**/__snapshots__",
35
+ "!**/*.test.*"
32
36
  ],
33
37
  "dependencies": {
34
- "@servicetitan/error-boundary": "40.2.2",
35
- "@servicetitan/startup-utils": "40.2.2",
38
+ "@servicetitan/error-boundary": "40.4.0",
39
+ "@servicetitan/startup-utils": "40.4.0",
36
40
  "mitt": "~3.0.1",
37
- "semver": "~7.8.5"
41
+ "semver": "^7.8.6"
38
42
  },
39
43
  "devDependencies": {
40
- "@servicetitan/anvil2": "^3.16.1",
41
- "@servicetitan/design-system": "~14.5.11",
42
- "@servicetitan/launchdarkly-service": "40.2.2",
43
- "@servicetitan/log-service": "40.2.2",
44
- "@servicetitan/react-ioc": "40.2.2",
44
+ "@servicetitan/anvil2": "^3.19.1",
45
+ "@servicetitan/design-system": "~14.5.12",
46
+ "@servicetitan/launchdarkly-service": "40.4.0",
47
+ "@servicetitan/log-service": "40.4.0",
48
+ "@servicetitan/react-ioc": "40.4.0",
45
49
  "@testing-library/dom": "^10.4.2",
46
50
  "@testing-library/jest-dom": "^7.0.1",
47
51
  "@testing-library/react": "^16.3.3",
48
52
  "@types/history": "~4.7.10",
49
53
  "@types/react": "~18.3.3",
50
54
  "@types/react-dom": "~18.3.0",
51
- "@types/semver": "~7.7.1",
55
+ "@types/semver": "^7.8.0",
52
56
  "history": "~4.10.1",
53
57
  "react": "~18.3.1",
54
58
  "react-dom": "~18.3.1",
@@ -57,9 +61,9 @@
57
61
  "peerDependencies": {
58
62
  "@servicetitan/anvil2": ">=1.5.0",
59
63
  "@servicetitan/design-system": ">=14.5.3",
60
- "@servicetitan/launchdarkly-service": "40.2.2",
61
- "@servicetitan/log-service": "40.2.2",
62
- "@servicetitan/react-ioc": "40.2.2",
64
+ "@servicetitan/launchdarkly-service": "40.4.0",
65
+ "@servicetitan/log-service": "40.4.0",
66
+ "@servicetitan/react-ioc": "40.4.0",
63
67
  "history": "~4.10.1",
64
68
  "react": ">=17.0.2",
65
69
  "react-dom": ">=17.0.2"
package/src/common.ts CHANGED
@@ -1,19 +1,33 @@
1
1
  import { type LDService } from '@servicetitan/launchdarkly-service';
2
2
  import { Log } from '@servicetitan/log-service';
3
3
  import { symbolToken } from '@servicetitan/react-ioc';
4
- import { ExposedDependencies } from '@servicetitan/startup-utils';
4
+ import { SharedDependencies } from '@servicetitan/startup-utils';
5
5
  import { EventBus } from './event-bus';
6
6
  import { HistoryManager } from './history-manager';
7
7
 
8
- export interface ExposedInstanceDependencies {
8
+ export interface SharedInstanceDependencies {
9
9
  launchDarkly?: { version: string; ldService?: LDService };
10
10
  }
11
11
 
12
+ /** @deprecated Use `SharedInstanceDependencies` */
13
+ export type ExposedInstanceDependencies = SharedInstanceDependencies;
14
+
12
15
  export const BASENAME_TOKEN = symbolToken<string>('BASENAME_TOKEN');
13
- export const EXPOSED_DEPENDENCIES_TOKEN = symbolToken<ExposedDependencies>(
16
+ export const SHARED_DEPENDENCIES_TOKEN = symbolToken<SharedDependencies>(
17
+ 'SHARED_DEPENDENCIES_TOKEN'
18
+ );
19
+ export const SHARED_INSTANCE_DEPENDENCIES_TOKEN = symbolToken<SharedInstanceDependencies>(
20
+ 'SHARED_INSTANCE_DEPENDENCIES_TOKEN'
21
+ );
22
+ /**
23
+ * @deprecated Use `SHARED_DEPENDENCIES_TOKEN`. Still provided to MFEs for consumers and
24
+ * older versions of web-components that read it; to be removed in a future major release.
25
+ */
26
+ export const EXPOSED_DEPENDENCIES_TOKEN = symbolToken<SharedDependencies>(
14
27
  'EXPOSED_DEPENDENCIES_TOKEN'
15
28
  );
16
- export const EXPOSED_INSTANCE_DEPENDENCIES_TOKEN = symbolToken<ExposedInstanceDependencies>(
29
+ /** @deprecated Use `SHARED_INSTANCE_DEPENDENCIES_TOKEN`. See `EXPOSED_DEPENDENCIES_TOKEN`. */
30
+ export const EXPOSED_INSTANCE_DEPENDENCIES_TOKEN = symbolToken<SharedInstanceDependencies>(
17
31
  'EXPOSED_INSTANCE_DEPENDENCIES_TOKEN'
18
32
  );
19
33
  export const IS_WEB_COMPONENT_TOKEN = symbolToken<boolean>('IS_WEB_COMPONENT_TOKEN');
@@ -23,8 +37,15 @@ export interface Entries {
23
37
  ldService?: LDService;
24
38
  logService?: Log;
25
39
  historyManager?: HistoryManager;
26
- exposedDependencies?: ExposedDependencies;
27
- exposedInstanceDependencies?: ExposedInstanceDependencies;
40
+ sharedDependencies?: SharedDependencies;
41
+ sharedInstanceDependencies?: SharedInstanceDependencies;
42
+ /**
43
+ * @deprecated Use `sharedDependencies`. Hosts still send this for MFEs built with older
44
+ * versions of web-components, and MFEs still read it from older hosts.
45
+ */
46
+ exposedDependencies?: SharedDependencies;
47
+ /** @deprecated Use `sharedInstanceDependencies`. See `exposedDependencies`. */
48
+ exposedInstanceDependencies?: SharedInstanceDependencies;
28
49
  eventBus?: EventBus;
29
50
  basename?: string;
30
51
  onReady?: () => void;
package/src/globals.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  /* eslint-disable @typescript-eslint/naming-convention */
2
2
  // eslint-disable-next-line spaced-comment
3
3
  /// <reference types="vite/client" /> — provides types for import.meta.env
4
- import { ExposedDependencies } from '@servicetitan/startup-utils';
5
- import { ExposedInstanceDependencies } from './common';
4
+ import { SharedDependencies } from '@servicetitan/startup-utils';
5
+ import { SharedInstanceDependencies } from './common';
6
6
 
7
7
  declare global {
8
- export const EXPOSED_DEPENDENCIES: ExposedDependencies | undefined;
9
- export const EXPOSED_INSTANCE_DEPENDENCIES: ExposedInstanceDependencies | undefined;
8
+ export const SHARED_DEPENDENCIES: SharedDependencies | undefined;
9
+ export const SHARED_INSTANCE_DEPENDENCIES: SharedInstanceDependencies | undefined;
10
+ export const EXPOSED_DEPENDENCIES: SharedDependencies | undefined;
11
+ export const EXPOSED_INSTANCE_DEPENDENCIES: SharedInstanceDependencies | undefined;
10
12
  export const WEB_COMPONENT_NAME: string | undefined;
11
13
  }
12
14
 
@@ -25,7 +27,17 @@ function get<T>(fetch: () => T) {
25
27
  }
26
28
  }
27
29
 
28
- const _EXPOSED_DEPENDENCIES =
30
+ /*
31
+ * The EXPOSED_* fallbacks keep hosts working when they are built with a version of
32
+ * startup that predates the SHARED_* names.
33
+ */
34
+ const _SHARED_DEPENDENCIES =
35
+ get(() => {
36
+ return SHARED_DEPENDENCIES;
37
+ }) ??
38
+ get(() => {
39
+ return import.meta.env.SHARED_DEPENDENCIES;
40
+ }) ??
29
41
  get(() => {
30
42
  return EXPOSED_DEPENDENCIES;
31
43
  }) ??
@@ -40,7 +52,13 @@ const _WEB_COMPONENT_NAME =
40
52
  get(() => {
41
53
  return import.meta.env.WEB_COMPONENT_NAME;
42
54
  });
43
- const _EXPOSED_INSTANCE_DEPENDENCIES =
55
+ const _SHARED_INSTANCE_DEPENDENCIES =
56
+ get(() => {
57
+ return SHARED_INSTANCE_DEPENDENCIES;
58
+ }) ??
59
+ get(() => {
60
+ return import.meta.env.SHARED_INSTANCE_DEPENDENCIES;
61
+ }) ??
44
62
  get(() => {
45
63
  return EXPOSED_INSTANCE_DEPENDENCIES;
46
64
  }) ??
@@ -49,7 +67,7 @@ const _EXPOSED_INSTANCE_DEPENDENCIES =
49
67
  });
50
68
 
51
69
  export {
52
- _EXPOSED_DEPENDENCIES as EXPOSED_DEPENDENCIES,
53
- _EXPOSED_INSTANCE_DEPENDENCIES as EXPOSED_INSTANCE_DEPENDENCIES,
70
+ _SHARED_DEPENDENCIES as SHARED_DEPENDENCIES,
71
+ _SHARED_INSTANCE_DEPENDENCIES as SHARED_INSTANCE_DEPENDENCIES,
54
72
  _WEB_COMPONENT_NAME as WEB_COMPONENT_NAME,
55
73
  };
package/src/loader.tsx CHANGED
@@ -2,7 +2,7 @@ import { ErrorBoundary } from '@servicetitan/error-boundary';
2
2
  import { type LDService } from '@servicetitan/launchdarkly-service';
3
3
  import { Log } from '@servicetitan/log-service';
4
4
  import { useOptionalDependencies } from '@servicetitan/react-ioc';
5
- import { ExposedDependencies } from '@servicetitan/startup-utils';
5
+ import { SharedDependencies } from '@servicetitan/startup-utils';
6
6
  import {
7
7
  ReactElement,
8
8
  ReactNode,
@@ -14,16 +14,11 @@ import {
14
14
  useMemo,
15
15
  useRef,
16
16
  } from 'react';
17
- import {
18
- EXPOSED_DEPENDENCIES_TOKEN,
19
- EXPOSED_INSTANCE_DEPENDENCIES_TOKEN,
20
- ExposedInstanceDependencies,
21
- GetJsonError,
22
- } from './common';
17
+ import { GetJsonError, SharedInstanceDependencies } from './common';
23
18
  import { MFEContextData } from './contexts/mfe-data-context';
24
19
  import { Delayed } from './delayed';
25
20
  import { EVENT_BUS_TOKEN, EventBus } from './event-bus';
26
- import { EXPOSED_DEPENDENCIES, EXPOSED_INSTANCE_DEPENDENCIES } from './globals';
21
+ import { useHostSharedDependencies } from './use-host-shared-dependencies';
27
22
  import {
28
23
  getBundleInfo,
29
24
  getLDServiceToken,
@@ -76,11 +71,8 @@ const UnrestrictedLoader = <T,>(props: UnrestrictedLoaderProps<T>, ref: Ref<Load
76
71
  const { loadingFallback, loadingFallbackDelayed = true } = props;
77
72
 
78
73
  const bus = useEventBus();
79
- const [logService, exposedDependencies = EXPOSED_DEPENDENCIES, eventBus = bus] =
80
- useOptionalDependencies(Log, EXPOSED_DEPENDENCIES_TOKEN, EVENT_BUS_TOKEN);
81
- let [exposedInstanceDependencies = EXPOSED_INSTANCE_DEPENDENCIES] = useOptionalDependencies(
82
- EXPOSED_INSTANCE_DEPENDENCIES_TOKEN
83
- );
74
+ const [logService, eventBus = bus] = useOptionalDependencies(Log, EVENT_BUS_TOKEN);
75
+ const [hostSharedDependencies, sharedInstanceDependencies] = useHostSharedDependencies();
84
76
  const [ldService] = useOptionalDependencies(getLDServiceToken() ?? Symbol());
85
77
 
86
78
  const LoadingFallback = useMemo(() => {
@@ -93,9 +85,9 @@ const UnrestrictedLoader = <T,>(props: UnrestrictedLoaderProps<T>, ref: Ref<Load
93
85
  return getFallback(props.errorFallback, message);
94
86
  }, [props.errorFallback, src]);
95
87
 
96
- exposedInstanceDependencies = useMemo(
97
- () => ensureLDService(exposedInstanceDependencies, ldService),
98
- [exposedInstanceDependencies, ldService]
88
+ const sharedInstanceDependenciesWithLD = useMemo(
89
+ () => ensureLDService(sharedInstanceDependencies, ldService),
90
+ [sharedInstanceDependencies, ldService]
99
91
  );
100
92
 
101
93
  const Loader = useMemo(
@@ -103,8 +95,8 @@ const UnrestrictedLoader = <T,>(props: UnrestrictedLoaderProps<T>, ref: Ref<Load
103
95
  lazyWebComponent({
104
96
  basename,
105
97
  cache,
106
- exposedDependencies,
107
- exposedInstanceDependencies,
98
+ hostSharedDependencies,
99
+ sharedInstanceDependencies: sharedInstanceDependenciesWithLD,
108
100
  eventBus,
109
101
  fallbackSrc,
110
102
  isHeadless,
@@ -116,8 +108,8 @@ const UnrestrictedLoader = <T,>(props: UnrestrictedLoaderProps<T>, ref: Ref<Load
116
108
  [
117
109
  basename,
118
110
  cache,
119
- exposedDependencies,
120
- exposedInstanceDependencies,
111
+ hostSharedDependencies,
112
+ sharedInstanceDependenciesWithLD,
121
113
  eventBus,
122
114
  fallbackSrc,
123
115
  isHeadless,
@@ -148,8 +140,8 @@ export const Loader = forwardRef(UnrestrictedLoader) as <T = {}>(
148
140
  ) => ReturnType<typeof UnrestrictedLoader>;
149
141
 
150
142
  type LazyLoaderProps = UnrestrictedLoaderProps<any> & {
151
- exposedDependencies?: ExposedDependencies;
152
- exposedInstanceDependencies?: ExposedInstanceDependencies;
143
+ hostSharedDependencies?: SharedDependencies;
144
+ sharedInstanceDependencies?: SharedInstanceDependencies;
153
145
  eventBus: EventBus;
154
146
  logService?: Log;
155
147
  cache: Required<UnrestrictedLoaderProps<any>>['cache'];
@@ -159,8 +151,8 @@ function lazyWebComponent(props: LazyLoaderProps) {
159
151
  const {
160
152
  basename,
161
153
  cache,
162
- exposedDependencies,
163
- exposedInstanceDependencies,
154
+ hostSharedDependencies,
155
+ sharedInstanceDependencies,
164
156
  eventBus,
165
157
  fallbackSrc,
166
158
  isHeadless,
@@ -171,27 +163,31 @@ function lazyWebComponent(props: LazyLoaderProps) {
171
163
  } = props;
172
164
 
173
165
  return lazy<(_: LoaderDataProps) => JSX.Element | null>(async () => {
166
+ if (!src) {
167
+ throw new Error('Loader src is empty');
168
+ }
169
+
174
170
  const bundleInfo = await getBundleInfo({
175
171
  cache,
176
172
  mainPackageUrl: src,
177
173
  fallbackPackageUrl: fallbackSrc,
178
174
  isHeadless,
179
- exposedDependencies,
180
- exposedInstanceDependencies,
175
+ hostSharedDependencies,
176
+ sharedInstanceDependencies,
181
177
  retries,
182
178
  onRequestError,
183
179
  });
184
180
 
185
181
  validateBundleInfo(bundleInfo, {
186
- exposedDependencies,
187
- exposedInstanceDependencies,
182
+ hostSharedDependencies,
183
+ sharedInstanceDependencies,
188
184
  logService,
189
185
  packageUrl: src,
190
186
  });
191
187
 
192
188
  await loadScripts(bundleInfo);
193
189
 
194
- const hostLDService = exposedInstanceDependencies?.launchDarkly?.ldService;
190
+ const hostLDService = sharedInstanceDependencies?.launchDarkly?.ldService;
195
191
  const hostSupportsVersionedLDClient = typeof hostLDService?.getVersionClient === 'function';
196
192
  const ldService =
197
193
  bundleInfo.mfeHasCompatibleLaunchDarklyVersion ||
@@ -204,8 +200,8 @@ function lazyWebComponent(props: LazyLoaderProps) {
204
200
  basename,
205
201
  bundleInfo,
206
202
  eventBus,
207
- exposedDependencies,
208
- exposedInstanceDependencies,
203
+ hostSharedDependencies,
204
+ sharedInstanceDependencies,
209
205
  ldService,
210
206
  logService,
211
207
  }),
@@ -223,18 +219,18 @@ function getFallback(
223
219
  }
224
220
 
225
221
  function isLocalHost(source: string) {
226
- return ['localhost', '127.0.0.1'].some(host => source.indexOf(host) >= 0);
222
+ return !!source && ['localhost', '127.0.0.1'].some(host => source.indexOf(host) >= 0);
227
223
  }
228
224
 
229
225
  function ensureLDService(
230
- exposedInstanceDependencies?: ExposedInstanceDependencies,
226
+ sharedInstanceDependencies?: SharedInstanceDependencies,
231
227
  ldService?: LDService
232
228
  ) {
233
- const launchDarkly = exposedInstanceDependencies?.launchDarkly;
229
+ const launchDarkly = sharedInstanceDependencies?.launchDarkly;
234
230
  if (launchDarkly?.version && !launchDarkly.ldService && ldService) {
235
- return { ...exposedInstanceDependencies, launchDarkly: { ...launchDarkly, ldService } };
231
+ return { ...sharedInstanceDependencies, launchDarkly: { ...launchDarkly, ldService } };
236
232
  }
237
- return exposedInstanceDependencies;
233
+ return sharedInstanceDependencies;
238
234
  }
239
235
 
240
236
  function useEventBus() {
@@ -0,0 +1,11 @@
1
+ import type { Metadata } from '../../types';
2
+
3
+ /*
4
+ * Design system's Table bundles the Kendo grid as its own dependency, so MFEs that use it
5
+ * don't list the grid themselves.
6
+ */
7
+ const KENDO_GRID_PACKAGES = ['@progress/kendo-react-grid', '@servicetitan/design-system'];
8
+
9
+ export function getMFEMaybeUsesKendoGrid(dependencies: Metadata['dependencies']) {
10
+ return KENDO_GRID_PACKAGES.some(name => !!dependencies?.[name]);
11
+ }
@@ -0,0 +1,2 @@
1
+ export * from './get-mfe-maybe-uses-kendo-grid';
2
+ export * from './set-kendo-scrollbar-width';
@@ -0,0 +1,27 @@
1
+ const KENDO_SCROLLBAR_WIDTH = '--kendo-scrollbar-width';
2
+
3
+ /*
4
+ * Kendo measures the scrollbar on document.body, where host scrollbar styles apply but MFE
5
+ * styles don't. Measure inside the MFE's shadow root instead, and set the result on the MFE
6
+ * element and its portals so it overrides the value they inherit from the body.
7
+ */
8
+ export function setKendoScrollbarWidth(element: HTMLElement, elementName: string) {
9
+ const root = element.shadowRoot;
10
+ if (!root) {
11
+ return;
12
+ }
13
+
14
+ const probe = document.createElement('div');
15
+ probe.style.cssText = 'overflow:scroll;overflow-x:hidden;zoom:1;clear:both;display:block';
16
+ probe.innerHTML = '&nbsp;';
17
+ root.appendChild(probe);
18
+ const width = `${probe.offsetWidth - probe.scrollWidth}px`;
19
+ probe.remove();
20
+
21
+ const portals = document.querySelectorAll<HTMLElement>(
22
+ `[data-mfe-portal-name="${elementName}"]`
23
+ );
24
+ for (const target of [element, ...portals]) {
25
+ target.style.setProperty(KENDO_SCROLLBAR_WIDTH, width);
26
+ }
27
+ }
package/src/register.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import { type LDService } from '@servicetitan/launchdarkly-service';
2
2
  import { Log } from '@servicetitan/log-service';
3
3
  import { Provider } from '@servicetitan/react-ioc';
4
- import { ExposedDependencies } from '@servicetitan/startup-utils';
4
+ import { SharedDependencies } from '@servicetitan/startup-utils';
5
5
  import { ComponentType, FC, ReactElement, useEffect } from 'react';
6
6
  import { Anvil1Providers } from './anvil1-providers';
7
7
  import { Anvil2Providers } from './anvil2-providers';
@@ -10,10 +10,12 @@ import {
10
10
  Entries,
11
11
  EXPOSED_DEPENDENCIES_TOKEN,
12
12
  EXPOSED_INSTANCE_DEPENDENCIES_TOKEN,
13
- ExposedInstanceDependencies,
14
13
  IS_WEB_COMPONENT_TOKEN,
15
14
  IWebComponent,
16
15
  RENDER_ROOT_TOKEN,
16
+ SHARED_DEPENDENCIES_TOKEN,
17
+ SHARED_INSTANCE_DEPENDENCIES_TOKEN,
18
+ SharedInstanceDependencies,
17
19
  } from './common';
18
20
  import { MFEDataContext } from './contexts/mfe-data-context';
19
21
  import { MFEMetadataContext } from './contexts/mfe-metadata-context';
@@ -39,6 +41,19 @@ function createLink(url: string, onLoad: () => void) {
39
41
 
40
42
  const Placeholder: FC = () => <div style={{ display: 'none' }} />;
41
43
 
44
+ /*
45
+ * Hosts built with older versions of web-components only send the deprecated
46
+ * `exposedDependencies` and `exposedInstanceDependencies` entries.
47
+ */
48
+ function normalizeEntries(entries: Entries): Entries {
49
+ const { exposedDependencies, exposedInstanceDependencies, ...rest } = entries;
50
+ return {
51
+ ...rest,
52
+ sharedDependencies: rest.sharedDependencies ?? exposedDependencies,
53
+ sharedInstanceDependencies: rest.sharedInstanceDependencies ?? exposedInstanceDependencies,
54
+ };
55
+ }
56
+
42
57
  export interface RegisterOptions {
43
58
  legacyRoot?: boolean;
44
59
  sharedDependenciesNames?: string[];
@@ -61,8 +76,8 @@ export function register(Component: ComponentType, light: boolean, options?: Reg
61
76
  private ldService?: LDService;
62
77
  private logService?: Log;
63
78
  private historyManager?: HistoryManager;
64
- private exposedDependencies?: ExposedDependencies;
65
- private exposedInstanceDependencies?: ExposedInstanceDependencies;
79
+ private sharedDependencies?: SharedDependencies;
80
+ private sharedInstanceDependencies?: SharedInstanceDependencies;
66
81
  private eventBus?: EventBus;
67
82
  private basename?: string;
68
83
  private onReady?: () => void;
@@ -128,7 +143,7 @@ export function register(Component: ComponentType, light: boolean, options?: Reg
128
143
  }
129
144
 
130
145
  this.view?.unmount();
131
- document.body?.removeChild(this.portal!.host);
146
+ this.portal!.host.remove();
132
147
  this.root = undefined;
133
148
  this.portal = undefined;
134
149
  this.portalAnvilContainer = undefined;
@@ -146,7 +161,7 @@ export function register(Component: ComponentType, light: boolean, options?: Reg
146
161
  }
147
162
 
148
163
  provide = (entries: Entries) => {
149
- for (const [key, value] of Object.entries(entries)) {
164
+ for (const [key, value] of Object.entries(normalizeEntries(entries))) {
150
165
  this[key as keyof IWebComponent] = value;
151
166
  }
152
167
 
@@ -223,13 +238,25 @@ export function register(Component: ComponentType, light: boolean, options?: Reg
223
238
  provide: HistoryManager,
224
239
  useValue: this.historyManager,
225
240
  },
241
+ {
242
+ provide: SHARED_DEPENDENCIES_TOKEN,
243
+ useValue: this.sharedDependencies,
244
+ },
245
+ {
246
+ provide: SHARED_INSTANCE_DEPENDENCIES_TOKEN,
247
+ useValue: this.sharedInstanceDependencies,
248
+ },
249
+ /*
250
+ * Deprecated tokens, still provided for consumers and nested
251
+ * loaders built with older versions of web-components
252
+ */
226
253
  {
227
254
  provide: EXPOSED_DEPENDENCIES_TOKEN,
228
- useValue: this.exposedDependencies,
255
+ useValue: this.sharedDependencies,
229
256
  },
230
257
  {
231
258
  provide: EXPOSED_INSTANCE_DEPENDENCIES_TOKEN,
232
- useValue: this.exposedInstanceDependencies,
259
+ useValue: this.sharedInstanceDependencies,
233
260
  },
234
261
  { provide: BASENAME_TOKEN, useValue: this.basename },
235
262
  { provide: EVENT_BUS_TOKEN, useValue: this.eventBus },
@@ -0,0 +1,26 @@
1
+ import { useOptionalDependencies } from '@servicetitan/react-ioc';
2
+ import {
3
+ EXPOSED_DEPENDENCIES_TOKEN,
4
+ EXPOSED_INSTANCE_DEPENDENCIES_TOKEN,
5
+ SHARED_DEPENDENCIES_TOKEN,
6
+ SHARED_INSTANCE_DEPENDENCIES_TOKEN,
7
+ } from './common';
8
+ import { SHARED_DEPENDENCIES, SHARED_INSTANCE_DEPENDENCIES } from './globals';
9
+
10
+ /**
11
+ * Resolves the host's shared dependencies from the DI container, falling back to the
12
+ * deprecated EXPOSED_* tokens (still provided by consumers and older versions of
13
+ * web-components) and then to the build-time globals.
14
+ */
15
+ export function useHostSharedDependencies() {
16
+ const [shared, deprecatedShared, instance, deprecatedInstance] = useOptionalDependencies(
17
+ SHARED_DEPENDENCIES_TOKEN,
18
+ EXPOSED_DEPENDENCIES_TOKEN,
19
+ SHARED_INSTANCE_DEPENDENCIES_TOKEN,
20
+ EXPOSED_INSTANCE_DEPENDENCIES_TOKEN
21
+ );
22
+ return [
23
+ shared ?? deprecatedShared ?? SHARED_DEPENDENCIES,
24
+ instance ?? deprecatedInstance ?? SHARED_INSTANCE_DEPENDENCIES,
25
+ ] as const;
26
+ }