The warung’s app is open in three tabs, each holding a handy talky: one tab calls postMessage, so who hears it? Real BroadcastChannels, also to your other…
Why it matters
Syncing tabs is a real need: logging out everywhere, a cart that updates along, "you are logged in in another tab". People used the storage event of localStorage for it. BroadcastChannel is the clean API made for exactly that.
The key idea
A broadcast for the others, per object, after the script
Common mistakes
Forgetting channel.close() The channel keeps listening after its component unmounts, so its old handler runs too (twice, after a re-render). Call close() in the useEffect cleanup.
Try it in this playground
Send from A: only B and C receive Run it to the end. Mrs. Sari never hears herself.
See 'terkirim' print first The message is only delivered once the sending script is done.
Another name: tab C hears nothing Pick 'warung-v2' for tab C, then send.
An old channel left open: received twice Tab B's old object still listens, so its handler runs twice.