Issue Bug Under Review Orphaned

#93270BroadcastMessage.fromData() is not idempotent

Benjamin Franzke 01/12/21, 06:35 updated 11/29/21, 14:03

Description

If BroadcastMessage is recreated using BroadcastMessage.fromData() it does not retain the original object structure. This is because BroadcastMessage.fromData() nests the entrire data (which includes a payload property itself) into another wrapping payload property.

Given following JavaScript code (executable in a Browser console in a window of the TYPO3 Backend):

window.require(['TYPO3/CMS/Backend/BroadcastMessage'], ({BroadcastMessage}) => {
  const bm1 = new BroadcastMessage('component', 'eventName', {foo: 'bar'})
  // Create bm2 from bm1, as if bm1 has been sent via broadcastchannel
  const bm2 = BroadcastMessage.fromData(bm1)
  console.log('bm1', bm1.payload)
  console.log('bm2', bm2.payload)
})

The expected result/output is that payload contains the same value for both BroadcastMessage instances:

bm1 {foo: "bar"}
bm2 {foo: "bar"}

While it actually is:

bm1 {foo: "bar"}
bm2 {payload: {foo: "bar"}}

BroadcastMessage.fromData() should be fixed to be idempotent, while keeping backwards compatibility (to existing event-subscribers) by doing the “additional” payload wrapping in BroadcastMessage.createCustomEvent. The “good” thing is, that BroadcastMessage isn’t used directly by subscribers, it is transformed into a CustomEvent, therefore this can be fixed without breaking BC.

Reviews 1

History 615

  1. Gerrit Code Review pushed patch set 1 for master to change 67432 status New Under Review <span data-processor="relativetime" data-value="2021-01-12T11:10:45+00:00" > 01/12/21, 11:10 </span>