Skip to content

Commit 4a3a2e7

Browse files
committed
fix(NoraFloatingInspector): prevent Segment crash when trying to show a Piece with an invalid Nora previewPayload
1 parent 8f17c0a commit 4a3a2e7

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

meteor/client/ui/FloatingInspectors/L3rdFloatingInspector.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ export const L3rdFloatingInspector: React.FunctionComponent<IProps> = ({
8484

8585
const { style: floatingInspectorStyle } = useInspectorPosition(position, ref, showMiniInspector)
8686

87-
return noraContent && noraContent.previewPayload && noraContent.previewRenderer ? (
87+
const hasValidPreviewPayload =
88+
noraContent?.previewPayload && noraContent?.previewPayload && noraContent.previewPayload.toString() !== '{}'
89+
90+
return hasValidPreviewPayload && noraContent.previewRenderer ? (
8891
showMiniInspector ? (
8992
<NoraFloatingInspector ref={ref} noraContent={noraContent} style={floatingInspectorStyle} />
9093
) : null

meteor/client/ui/FloatingInspectors/NoraFloatingInspector.tsx

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { JSONBlobParse, NoraContent } from '@sofie-automation/blueprints-integration'
1+
import { JSONBlobParse, NoraContent, NoraPayload } from '@sofie-automation/blueprints-integration'
22
import React, { useEffect, useImperativeHandle } from 'react'
33
import _ from 'underscore'
44
import { getNoraContentSteps } from '../SegmentContainer/PieceMultistepChevron'
@@ -86,35 +86,39 @@ export class NoraPreviewRenderer extends React.Component<{}, IStateHeader> {
8686
}
8787

8888
private postNoraEvent(contentWindow: Window, noraContent: NoraContent) {
89-
const payload = JSONBlobParse(noraContent.previewPayload)
90-
91-
contentWindow.postMessage(
92-
{
93-
event: 'nora',
94-
contentToShow: {
95-
manifest: payload.manifest,
96-
template: {
97-
event: 'preview',
98-
name: payload.template.name,
99-
channel: 'gfx1',
100-
layer: payload.template.layer,
101-
system: 'html',
89+
try {
90+
const payload = JSONBlobParse<NoraPayload>(noraContent.previewPayload)
91+
92+
contentWindow.postMessage(
93+
{
94+
event: 'nora',
95+
contentToShow: {
96+
manifest: payload.manifest,
97+
template: {
98+
event: 'preview',
99+
name: payload.template.name,
100+
channel: 'gfx1',
101+
layer: payload.template.layer,
102+
system: 'html',
103+
},
104+
content: {
105+
...payload.content,
106+
_valid: false,
107+
},
108+
timing: {
109+
duration: '00:05',
110+
in: 'auto',
111+
out: 'auto',
112+
timeIn: '00:00',
113+
},
114+
step: payload.step,
102115
},
103-
content: {
104-
...payload.content,
105-
_valid: false,
106-
},
107-
timing: {
108-
duration: '00:05',
109-
in: 'auto',
110-
out: 'auto',
111-
timeIn: '00:00',
112-
},
113-
step: payload.step,
114116
},
115-
},
116-
'*'
117-
)
117+
'*'
118+
)
119+
} catch (e) {
120+
console.error(`Error in NoraPreviewRenderer.postNoraEvent: ${e}`, e)
121+
}
118122
}
119123

120124
private _show() {

0 commit comments

Comments
 (0)