Skip to content

Commit

Permalink
fix: prevent sending updated props to plugin when props do not change…
Browse files Browse the repository at this point in the history
… [LIBS-514]
  • Loading branch information
tomzemp authored Dec 20, 2023
2 parents 0724236 + 0ccae45 commit 86c6f75
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions services/plugin/src/Plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ export const Plugin = ({
}
}, [height, width])

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

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

if (iframeRef?.current) {
const iframeProps = {
...propsToPass,
...memoizedPropsToPass,
alertsAdd,
setPluginHeight,
setPluginWidth,
Expand Down Expand Up @@ -128,7 +140,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 86c6f75

Please sign in to comment.