Skip to content

Commit

Permalink
fix: don't send width resizer if client width is set
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVandivier committed Dec 18, 2024
1 parent 59a4b99 commit 9181270
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions services/plugin/src/Plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ export const Plugin = ({
useState<boolean>(false)

const [inErrorState, setInErrorState] = useState<boolean>(false)
// height and width values to be set by callbacks passed to the plugin
// (these default sizes will be quickly overwritten by the plugin)
// in order to behave like a normal block element, by default, the height
// will be set by plugin contents, this state will be used
const [resizedHeight, setPluginHeight] = useState<number>(150)
// ...and by default, plugin width will be defined by the container
// (width = 100%), so this state won't be used unless the `clientWidth`
// prop is used to have plugin width defined by plugin contents
const [resizedWidth, setPluginWidth] = useState<number>(500)

// since we do not know what props are passed, the dependency array has to be keys of whatever is standard prop
Expand Down Expand Up @@ -91,8 +98,10 @@ export const Plugin = ({
const iframeProps = {
...memoizedPropsToPass,
alertsAdd,
// if a dimension is specified or container driven, don't send
// a resize callback to the plugin
setPluginHeight: !height ? setPluginHeight : null,
setPluginWidth: !width ? setPluginWidth : null,
setPluginWidth: !width && clientWidth ? setPluginWidth : null,
setInErrorState,
setCommunicationReceived,
clientWidth,
Expand Down Expand Up @@ -152,8 +161,10 @@ export const Plugin = ({
ref={iframeRef}
src={pluginSource}
className={className}
// if clientWidth is set, then we want width to be set by plugin.
// otherwise,
width={clientWidth ? resizedWidth : width ?? '100%'}
height={height ?? resizedHeight + 'px'}
height={height ?? resizedHeight}
style={{ border: 'none' }}
/>
)
Expand Down

0 comments on commit 9181270

Please sign in to comment.