Skip to content

Commit 1936675

Browse files
committed
Fix simultaneous messages cause message id conflicts & reset imcContext initialization map when tab is closed
1 parent 4b1e199 commit 1936675

File tree

14 files changed

+58
-15
lines changed

14 files changed

+58
-15
lines changed

.changeset/crazy-cities-stand.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 simultaneous messages cause message id conflicts

.changeset/pre.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"chubby-insects-shake",
2222
"clean-mangos-swim",
2323
"cold-shrimps-give",
24+
"crazy-cities-stand",
2425
"cruel-waves-double",
2526
"cruel-zoos-play",
2627
"curvy-places-wash",

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.48
4+
5+
### Patch Changes
6+
7+
- Fix simultaneous messages cause message id conflicts
8+
- Updated dependencies
9+
- @pulse-editor/shared-utils@0.1.1-alpha.48
10+
311
## 0.1.1-alpha.47
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.47",
3+
"version": "0.1.1-alpha.48",
44
"main": "dist/main.js",
55
"files": [
66
"dist"
@@ -38,7 +38,7 @@
3838
"typescript-eslint": "^8.30.1"
3939
},
4040
"peerDependencies": {
41-
"@pulse-editor/shared-utils": "0.1.1-alpha.47",
41+
"@pulse-editor/shared-utils": "0.1.1-alpha.48",
4242
"react": "^19.0.0",
4343
"react-dom": "^19.0.0"
4444
}

npm-packages/react-api/src/providers/snapshot-provider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export default function SnapshotProvider({
3333
const { states } = message.payload;
3434

3535
// Update all states in the context
36+
console.log("Restoring snapshot states:", states);
3637
setStates((prev) => ({ ...states }));
3738
},
3839
],

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.48
4+
5+
### Patch Changes
6+
7+
- Fix simultaneous messages cause message id conflicts
8+
39
## 0.1.1-alpha.47
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.47",
3+
"version": "0.1.1-alpha.48",
44
"main": "dist/main.js",
55
"files": [
66
"dist"

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ export class InterModuleCommunication {
5757
type !== IMCMessageTypeEnum.SignalGetWindowId
5858
) {
5959
console.warn(
60-
`Duplicate message received with message ID: ${messageId}. Ignoring this message. Message: ${JSON.stringify(
60+
`[${
61+
this.thisWindowId
62+
}]: Duplicate message received with message ID: ${messageId}. Ignoring this message. Message: ${JSON.stringify(
6163
event.data
6264
)}`
6365
);

npm-packages/shared-utils/src/imc/message-sender.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { v4 } from "uuid";
12
import { IMCMessage, IMCMessageTypeEnum } from "../types/types";
23

34
export class MessageSender {
@@ -25,7 +26,7 @@ export class MessageSender {
2526
abortSignal?: AbortSignal
2627
): Promise<any> {
2728
// Generate a unique id for the message using timestamp
28-
const id = new Date().getTime().toString();
29+
const id = v4() + new Date().getTime().toString();
2930
const message: IMCMessage = {
3031
id,
3132
type: handlingType,

web/components/app-loaders/sandbox-app-loader.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export default function SandboxAppLoader({
5757
// If the view Id changes (e.g. when switching file but not extension),
5858
// remove the old IMC channel and create a new one
5959
if (viewModel.viewId !== currentViewId) {
60-
if (currentViewId && imcContext?.polyIMC?.hasChannel(currentViewId)) {
61-
imcContext.polyIMC.removeChannel(currentViewId);
60+
if (currentViewId && imcContext?.hasChannel(currentViewId)) {
61+
imcContext.removeChannel(currentViewId);
6262
}
6363
setCurrentViewId(viewModel.viewId);
6464
}

0 commit comments

Comments
 (0)