@openmrs/esm-react-utils 5.0.3-pre.827 → 5.0.3-pre.829

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-react-utils",
3
- "version": "5.0.3-pre.827",
3
+ "version": "5.0.3-pre.829",
4
4
  "license": "MPL-2.0",
5
5
  "description": "React utilities for OpenMRS.",
6
6
  "browser": "dist/openmrs-esm-react-utils.js",
@@ -56,11 +56,11 @@
56
56
  "react-i18next": "11.x"
57
57
  },
58
58
  "devDependencies": {
59
- "@openmrs/esm-api": "^5.0.3-pre.827",
60
- "@openmrs/esm-config": "^5.0.3-pre.827",
61
- "@openmrs/esm-error-handling": "^5.0.3-pre.827",
62
- "@openmrs/esm-extensions": "^5.0.3-pre.827",
63
- "@openmrs/esm-globals": "^5.0.3-pre.827",
59
+ "@openmrs/esm-api": "^5.0.3-pre.829",
60
+ "@openmrs/esm-config": "^5.0.3-pre.829",
61
+ "@openmrs/esm-error-handling": "^5.0.3-pre.829",
62
+ "@openmrs/esm-extensions": "^5.0.3-pre.829",
63
+ "@openmrs/esm-globals": "^5.0.3-pre.829",
64
64
  "dayjs": "^1.10.8",
65
65
  "i18next": "^19.6.0",
66
66
  "react": "^18.1.0",
@@ -69,5 +69,5 @@
69
69
  "rxjs": "^6.5.3",
70
70
  "webpack": "^5.88.0"
71
71
  },
72
- "gitHead": "f10655c2e7b7cff8cd43c7bb5b0aefb8069b5f27"
72
+ "gitHead": "9bab50b6efe1f74e6964adbce112fc0c8a67f2e6"
73
73
  }
package/src/Extension.tsx CHANGED
@@ -41,7 +41,8 @@ export const Extension: React.FC<ExtensionProps> = ({
41
41
  const [domElement, setDomElement] = useState<HTMLDivElement>();
42
42
  const { extension } = useContext(ComponentContext);
43
43
  const parcel = useRef<Parcel | null>(null);
44
- const updatePromise = useRef<Promise<null> | null>(null);
44
+ const updatePromise = useRef<Promise<void> | undefined>();
45
+ const rendering = useRef<boolean>(false);
45
46
 
46
47
  useEffect(() => {
47
48
  if (wrap) {
@@ -65,7 +66,15 @@ export const Extension: React.FC<ExtensionProps> = ({
65
66
  );
66
67
 
67
68
  useEffect(() => {
68
- if (domElement != null && extension && !parcel.current) {
69
+ if (
70
+ domElement != null &&
71
+ extension?.extensionSlotName &&
72
+ extension.extensionSlotModuleName &&
73
+ extension.extensionSlotModuleName &&
74
+ !parcel.current &&
75
+ !rendering.current
76
+ ) {
77
+ rendering.current = true;
69
78
  renderExtension(
70
79
  domElement,
71
80
  extension.extensionSlotName,
@@ -75,6 +84,7 @@ export const Extension: React.FC<ExtensionProps> = ({
75
84
  state
76
85
  ).then((newParcel) => {
77
86
  parcel.current = newParcel;
87
+ rendering.current = false;
78
88
  });
79
89
 
80
90
  return () => {
@@ -115,19 +125,19 @@ export const Extension: React.FC<ExtensionProps> = ({
115
125
 
116
126
  useEffect(() => {
117
127
  if (parcel.current && parcel.current.update) {
118
- if (parcel.current.getStatus() === "MOUNTED") {
119
- parcel.current.update({ ...state });
120
- } else if (parcel.current.getStatus() === "MOUNTING") {
121
- parcel.current.mountPromise.then(() => {
122
- if (parcel.current && parcel.current.update) {
128
+ Promise.all([parcel.current.mountPromise, updatePromise.current]).then(
129
+ () => {
130
+ if (parcel?.current?.update) {
123
131
  updatePromise.current = parcel.current.update({ ...state });
124
132
  }
125
- });
126
- }
133
+ }
134
+ );
127
135
  }
128
136
 
129
137
  return () => {
130
- updatePromise.current = null;
138
+ Promise.resolve(updatePromise.current).then(() => {
139
+ updatePromise.current = undefined;
140
+ });
131
141
  };
132
142
  }, [state]);
133
143