Skip to content

Commit

Permalink
fix: check memomized props for postMessage communication [LIBS-514]
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Jun 23, 2023
1 parent 3fdae5b commit b1a3a0a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions services/plugin/src/Plugin.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AlertsManagerContext } from '@dhis2/app-service-alerts'
import { useDataQuery } from '@dhis2/app-service-data'
import postRobot from 'post-robot'
import React, { useContext, useEffect, useRef, useState } from 'react'
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react'
import PluginError from './PluginError'

const appsInfoQuery = {
Expand Down Expand Up @@ -52,6 +52,13 @@ export const Plugin = ({

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

// since we do not know what props are passed, the dependency array has to be keys of whatever is standard prop
// eslint-disable-next-line react-hooks/exhaustive-deps
const memoizedPropsToPass = useMemo(
() => propsToPass,
[...Object.keys(propsToPass)]
)

useEffect(() => {
setCommunicationReceived(false)
}, [pluginEntryPoint])
Expand All @@ -66,7 +73,7 @@ export const Plugin = ({

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

if (data && !pluginEntryPoint) {
return (
Expand Down

0 comments on commit b1a3a0a

Please sign in to comment.