Skip to content

Commit

Permalink
fix: trigger props resend when iframe src changes [LIBS-488]
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Mar 30, 2023
1 parent 44b27c4 commit f4a6680
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions services/plugin/src/Plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,23 @@ export const Plugin = ({

const [communicationReceived, setCommunicationReceived] =
useState<boolean>(false)
const [prevCommunicationReceived, setPrevCommunicationReceived] =
useState<boolean>(false)

const [inErrorState, setInErrorState] = useState<boolean>(false)

useEffect(() => {
setCommunicationReceived(false)
}, [pluginSource])

useEffect(() => {
// if communicationReceived switches from false to true, the props have been sent
const prevCommunication = prevCommunicationReceived
setPrevCommunicationReceived(communicationReceived)
if (prevCommunication === false && communicationReceived === true) {
return
}

if (iframeRef?.current) {
const iframeProps = {
...propsToPass,
Expand Down Expand Up @@ -91,6 +104,8 @@ export const Plugin = ({
})
}
}
// prevCommunicationReceived update should not retrigger this hook
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [propsToPass, communicationReceived, inErrorState, alertsAdd])

if (data && !pluginEntryPoint) {
Expand Down

0 comments on commit f4a6680

Please sign in to comment.