-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Reproduction
- Send the test app to "saved messages"
- Open-close it a couple of times. You will see
beforeunload(orvisibilitychange) event count go up. - Open the app on another device. You will see that "webxdc.sendUpdate() worked..." is much higher than the corresponding event count.
This is because localStorage is per-device, and webxdc.setUpdateListener is shared.
The solution would be to add a unique ID for each device and only count webxdc updates from the current device in this piece of code:
Lines 14 to 48 in 72adcdc
| window.anotherWebxdcUpdateListener = function (update) { | |
| if (!update.payload?.isEventCounterUpdate) { | |
| return; | |
| } | |
| const { eventName } = update.payload; | |
| const newCount = | |
| eventNameToNumWebxdcUpdatesFromIt[eventName] += 1; | |
| updateWebxdcUpdatesFromListenerElement(eventName, newCount); | |
| } | |
| events.forEach(eventName => { | |
| container.append( | |
| h("strong", {}, eventName), " triggered ", h("strong", {id: eventName + "-counter"}, getInt(`docEvent.${eventName}`)), " times", | |
| ", webxdc.sendUpdate() worked ", | |
| h("strong", { id: eventName + "-counter-sendUpdate" }, ''), | |
| " times", | |
| h("br"), | |
| ); | |
| updateWebxdcUpdatesFromListenerElement( | |
| eventName, | |
| eventNameToNumWebxdcUpdatesFromIt[eventName] | |
| ); | |
| window.addEventListener(eventName, () => { | |
| let storageKey = `docEvent.${eventName}`; | |
| let count = getInt(storageKey) + 1; | |
| window.localStorage.setItem(storageKey, count); | |
| document.getElementById(eventName + "-counter").innerHTML = count; | |
| webxdc.sendUpdate({ | |
| payload: { | |
| isEventCounterUpdate: true, | |
| eventName: eventName, | |
| } | |
| }, `${eventName} event counter`); | |
| }); | |
| }); |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels