@cocreate/organizations 1.26.0 → 1.26.1

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 CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.26.1](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.26.0...v1.26.1) (2023-12-22)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * postMessage undefined ([ae5a9e2](https://github.com/CoCreate-app/CoCreate-organizations/commit/ae5a9e25ad1c771559f6cd08323aa6307a51a645))
7
+
1
8
  # [1.26.0](https://github.com/CoCreate-app/CoCreate-organizations/compare/v1.25.0...v1.26.0) (2023-11-25)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/organizations",
3
- "version": "1.26.0",
3
+ "version": "1.26.1",
4
4
  "description": "A simple organizations component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "organizations",
package/src/client.js CHANGED
@@ -138,11 +138,22 @@ async function getOrganizationFromServiceWorker() {
138
138
 
139
139
  // Send message to Service Worker
140
140
  const msg = new MessageChannel();
141
- navigator.serviceWorker.ready
142
- .then(() => {
141
+
142
+ navigator.serviceWorker.ready.then(registration => {
143
+ if (navigator.serviceWorker.controller) {
144
+ // If there's an active controller, send the message
143
145
  navigator.serviceWorker.controller.postMessage({ action: 'getOrganization' }, [msg.port1]);
144
- })
145
- .catch(reject);
146
+ } else {
147
+ // Listen for a new service worker to start controlling the page
148
+ navigator.serviceWorker.addEventListener('controllerchange', () => {
149
+ if (navigator.serviceWorker.controller) {
150
+ navigator.serviceWorker.controller.postMessage({ action: 'getOrganization' }, [msg.port1]);
151
+ }
152
+ });
153
+ }
154
+ }).catch(error => {
155
+ console.error(reject);
156
+ });
146
157
  });
147
158
  }
148
159