Skip to content

Commit 748e40f

Browse files
committed
Fix IMC handshake async bug
1 parent 9a03469 commit 748e40f

File tree

15 files changed

+59
-37
lines changed

15 files changed

+59
-37
lines changed

.changeset/pre.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"true-suits-fly",
6666
"vast-places-rhyme",
6767
"weak-beers-watch",
68-
"wicked-spoons-fry"
68+
"wicked-spoons-fry",
69+
"young-jeans-behave"
6970
]
7071
}

.changeset/young-jeans-behave.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@pulse-editor/shared-utils": patch
3+
"@pulse-editor/react-api": patch
4+
---
5+
6+
Fix IMC handshake async bug

npm-packages/react-api/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @pulse-editor/react-api
22

3+
## 0.1.1-alpha.53
4+
5+
### Patch Changes
6+
7+
- Fix IMC handshake async bug
8+
- Updated dependencies
9+
- @pulse-editor/shared-utils@0.1.1-alpha.53
10+
311
## 0.1.1-alpha.52
412

513
### Patch Changes

npm-packages/react-api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pulse-editor/react-api",
3-
"version": "0.1.1-alpha.52",
3+
"version": "0.1.1-alpha.53",
44
"main": "dist/main.js",
55
"files": [
66
"dist"
@@ -37,7 +37,7 @@
3737
"typescript-eslint": "^8.30.1"
3838
},
3939
"peerDependencies": {
40-
"@pulse-editor/shared-utils": "0.1.1-alpha.52",
40+
"@pulse-editor/shared-utils": "0.1.1-alpha.53",
4141
"react": "^19.0.0",
4242
"react-dom": "^19.0.0"
4343
}

npm-packages/shared-utils/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @pulse-editor/shared-utils
22

3+
## 0.1.1-alpha.53
4+
5+
### Patch Changes
6+
7+
- Fix IMC handshake async bug
8+
39
## 0.1.1-alpha.52
410

511
### Patch Changes

npm-packages/shared-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pulse-editor/shared-utils",
3-
"version": "0.1.1-alpha.52",
3+
"version": "0.1.1-alpha.53",
44
"main": "dist/main.js",
55
"files": [
66
"dist"

npm-packages/shared-utils/src/imc/inter-module-communication.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,18 @@ export class InterModuleCommunication {
6464
const type = message.type;
6565

6666
// Return if the channel ID exists but does not match the current channel ID
67-
if (this.channelId !== undefined && channelId !== this.channelId) {
67+
// (channel ID can be undefined during initial handshake)
68+
if (
69+
this.channelId !== undefined &&
70+
channelId !== undefined &&
71+
channelId !== this.channelId
72+
) {
6873
return;
6974
}
7075

7176
if (
7277
this.messageRecords?.has(messageId) &&
73-
type !== IMCMessageTypeEnum.SignalGetWindowId
78+
type !== IMCMessageTypeEnum.SignalRequestOtherWindowId
7479
) {
7580
console.warn(
7681
`[${
@@ -89,7 +94,7 @@ export class InterModuleCommunication {
8994
);
9095
}
9196

92-
if (message.from !== undefined) {
97+
if (message.from !== undefined && message.type !== IMCMessageTypeEnum.SignalIgnore) {
9398
console.log(
9499
`Module ${this.thisWindowId} received message from module ${
95100
message.from
@@ -122,7 +127,7 @@ export class InterModuleCommunication {
122127
}
123128

124129
const message = event.data;
125-
const otherWindowId = message.windowId;
130+
const otherWindowId = message.payload;
126131
this.otherWindowId = otherWindowId;
127132

128133
const sender = new MessageSender(
@@ -149,7 +154,7 @@ export class InterModuleCommunication {
149154
this.otherWindow = window;
150155
this.otherWindow.postMessage(
151156
{
152-
type: IMCMessageTypeEnum.SignalGetWindowId,
157+
type: IMCMessageTypeEnum.SignalRequestOtherWindowId,
153158
from: this.thisWindowId,
154159
},
155160
"*"
@@ -237,7 +242,7 @@ export class InterModuleCommunication {
237242

238243
// Set get window ID handler in the receiver handler map.
239244
this.receiverHandlerMap?.set(
240-
IMCMessageTypeEnum.SignalGetWindowId,
245+
IMCMessageTypeEnum.SignalRequestOtherWindowId,
241246
async (senderWindow: Window, message: IMCMessage) => {
242247
console.log(
243248
"Received window ID request. Sending current window ID to other window: "
@@ -246,16 +251,8 @@ export class InterModuleCommunication {
246251
if (!id) {
247252
throw new Error("This window ID is not defined.");
248253
}
249-
const msg: IMCMessage = {
250-
messageId: message.messageId,
251-
channelId: message.channelId,
252-
type: IMCMessageTypeEnum.SignalReturnWindowId,
253-
payload: {
254-
windowId: id,
255-
},
256-
from: id,
257-
};
258-
senderWindow.postMessage(msg, "*");
254+
255+
return id;
259256
}
260257
);
261258

npm-packages/shared-utils/src/imc/poly-imc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export class ConnectionListener {
219219
message: IMCMessage,
220220
abortSignal?: AbortSignal
221221
) => {
222-
this.handleExtReady(senderWindow, message, abortSignal);
222+
await this.handleExtReady(senderWindow, message, abortSignal);
223223
},
224224
],
225225
])

npm-packages/shared-utils/src/types/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ export enum IMCMessageTypeEnum {
5858
// #endregion
5959

6060
// #region Signal messages
61-
SignalGetWindowId = "signal-get-window-id",
62-
SignalReturnWindowId = "signal-return-window-id",
61+
SignalRequestOtherWindowId = "signal-request-other-window-id",
6362
// A message to notify sender that the message
6463
// has been received and finished processing
6564
SignalAcknowledge = "signal-acknowledge",

web/components/marketplace/app/app-gallery.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export default function AppGallery() {
140140
]);
141141

142142
return (
143-
<div className="flex flex-col gap-y-2">
143+
<div className="h-full w-full grid grid-rows-[max-content_1fr] gap-y-2 overflow-y-auto">
144144
<div className="flex flex-col items-center">
145145
<Select
146146
label="Filter apps"
@@ -184,7 +184,7 @@ export default function AppGallery() {
184184
</p>
185185
</div>
186186
) : (
187-
<div className="grid grid-cols-2 gap-2 w-full">{previews}</div>
187+
<div className="grid grid-cols-2 gap-2 w-full h-full overflow-y-auto overflow-x-hidden px-1">{previews}</div>
188188
)}
189189
</div>
190190
);

0 commit comments

Comments
 (0)