Skip to content

Commit

Permalink
Revert "Revert "(fix) Fix issues with single-spa caused by naming ext…
Browse files Browse the repository at this point in the history
…ensions (openmrs#720)""

This reverts commit ba4190d.
  • Loading branch information
ibacher committed Jul 6, 2023
1 parent d9933a2 commit 77f0a46
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
5 changes: 4 additions & 1 deletion packages/framework/esm-extensions/src/render.ts
Expand Up @@ -8,6 +8,8 @@ export interface CancelLoading {
(): void;
}

let parcelCount = 0;

/**
* Mounts into a DOM node (representing an extension slot)
* a lazy-loaded component from *any* frontend module
Expand Down Expand Up @@ -58,10 +60,11 @@ export async function renderExtension(
});

const { default: result, ...lifecycle } = await load();
const id = parcelCount++;
parcel = mountRootParcel(
renderFunction({
...(result ?? lifecycle),
name: `${extensionName} in ${extensionSlotName}`,
name: `${extensionSlotName}/${extensionName}-${id}`,
}),
{
...additionalProps,
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/esm-framework/docs/API.md
Expand Up @@ -2386,7 +2386,7 @@ that registered an extension component for this slot.

#### Defined in

[packages/framework/esm-extensions/src/render.ts:16](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-extensions/src/render.ts#L16)
[packages/framework/esm-extensions/src/render.ts:18](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-extensions/src/render.ts#L18)

___

Expand Down
28 changes: 15 additions & 13 deletions packages/framework/esm-react-utils/src/Extension.tsx
Expand Up @@ -92,18 +92,19 @@ export const Extension: React.FC<ExtensionProps> = ({
const status = parcel.current.getStatus();
switch (status) {
case "MOUNTING":
parcel.current.mountPromise.then(parcel.current.unmount);
parcel.current.mountPromise.then(() => {
if (parcel.current?.getStatus() === "MOUNTED") {
parcel.current.unmount();
}
});
break;
case "MOUNTED":
parcel.current.unmount();
break;
case "UPDATING":
if (updatePromise.current) {
updatePromise.current.then(() => {
if (
parcel.current &&
parcel.current.getStatus() === "MOUNTED"
) {
if (parcel.current?.getStatus() === "MOUNTED") {
parcel.current.unmount();
}
});
Expand All @@ -124,21 +125,22 @@ export const Extension: React.FC<ExtensionProps> = ({
]);

useEffect(() => {
if (parcel.current && parcel.current.update) {
if (
parcel.current &&
parcel.current.update &&
parcel.current.getStatus() !== "UNMOUNTING"
) {
Promise.all([parcel.current.mountPromise, updatePromise.current]).then(
() => {
if (parcel?.current?.update) {
if (
parcel?.current?.getStatus() === "MOUNTED" &&
parcel.current.update
) {
updatePromise.current = parcel.current.update({ ...state });
}
}
);
}

return () => {
Promise.resolve(updatePromise.current).then(() => {
updatePromise.current = undefined;
});
};
}, [state]);

// The extension is rendered into the `<div>`. The `<div>` has relative
Expand Down

0 comments on commit 77f0a46

Please sign in to comment.