Project

General

Profile

Actions

Bug #93270

open

BroadcastMessage.fromData() is not idempotent

Added by Benjamin Franzke over 3 years ago. Updated over 2 years ago.

Status:
Under Review
Priority:
Should have
Assignee:
-
Category:
Backend JavaScript
Start date:
2021-01-12
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
11
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

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.

Actions #1

Updated by Benjamin Franzke over 3 years ago

  • Description updated (diff)
Actions #2

Updated by Gerrit Code Review over 3 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/67432

Actions #3

Updated by Gerrit Code Review over 3 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/67432

Actions #4

Updated by Gerrit Code Review over 3 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/67432

Actions #5

Updated by Gerrit Code Review over 3 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/67432

Actions #6

Updated by Benni Mack about 3 years ago

  • Target version changed from 11.1 to 11.2
Actions #7

Updated by Gerrit Code Review about 3 years ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/67432

Actions #8

Updated by Benni Mack almost 3 years ago

  • Target version changed from 11.2 to 11.3
Actions #9

Updated by Benni Mack almost 3 years ago

  • Target version changed from 11.3 to 11.4
Actions #10

Updated by Gerrit Code Review over 2 years ago

Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/67432

Actions #11

Updated by Benni Mack over 2 years ago

  • Target version changed from 11.4 to 11 LTS
Actions #12

Updated by Gerrit Code Review over 2 years ago

Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/67432

Actions #13

Updated by Gerrit Code Review over 2 years ago

Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/67432

Actions #14

Updated by Benni Mack over 2 years ago

  • Target version changed from 11 LTS to Candidate for patchlevel
Actions #15

Updated by Gerrit Code Review over 2 years ago

Patch set 9 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/67432

Actions

Also available in: Atom PDF