Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: trigger props resend when iframe src changes [LIBS-488] #1344

Merged
merged 6 commits into from
Sep 28, 2023

Conversation

tomzemp
Copy link
Member

@tomzemp tomzemp commented Mar 30, 2023

Implements LIBS-488


Key features

  1. retrigger post-robot communication on plugin src update
  2. (This is an indirect effect of addressing the above), but this also fixes an issue where there was an additional communication being sent after the initial successful communication

Description

This PR makes post-robot communication reinitialize when the iframe (plugin) src is changed.


Checklist

  • Have written Documentation
    • No new documentation is needed I think (plugins are unreleased, and I think this fix aligns with what would one logically expect, i.e. if you change the source, the Plugin wrapper will recognize that and load things appropriately again)
  • Has tests coverage
    • Tests are generally needed for these wrappers, but are being delayed until we are more definite about approach (i.e. this PR is part of work to define (on alpha branch) what we want to accomplish with plugin wrappers)

Known issues

  • This might be further optimized; I needed to track the previous state of communicationReceived to prevent an additional post-robot communication being triggered by this being updated. Edoardo suggested that this might be a ref, but the choice to have the communicationReceived retrigger communication is deliberate when communicationReceived is updated from true to false (used in error boundary reset). To avoid the unwanted communication when communicationReceived changes from false to true (side effect of successful communication), I need to exclude the previsouCommunicationReceived from the relevant useEffect hook...this would be nice to avoid, but I didn't want to look into this until we decide what we want to do with the error boundaries.

Screenshots

For example (observe that the plugin src changes, but the passed property (name: Tom Wakiki) remains updated (evidence that the post-robot communication is behaving as appropriate)
plugin_src_change

@tomzemp tomzemp marked this pull request as ready for review August 21, 2023 14:22

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

useEffect(() => {
setCommunicationReceived(false)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the essential refinement of this ticket...whenever the pluginEntryPoint changes now, the communicationReceived is set to false to note that communication has been lost.

The communicationReceived toggling to false will then trigger a resending of the props to the plugin.

// if communicationReceived switches from false to true, the props have been sent
const prevCommunication = prevCommunicationReceived
setPrevCommunicationReceived(communicationReceived)
if (prevCommunication === false && communicationReceived === true) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is done so that when communicationReceived toggles from false to true (after successful send of props), the props are not sent an additional time

@tomzemp tomzemp changed the base branch from alpha to master August 25, 2023 11:50
@tomzemp tomzemp changed the base branch from master to alpha August 25, 2023 11:50
@kabaros
Copy link
Contributor

kabaros commented Aug 28, 2023

out of curiosity, do we have a specific use-case here, where we need to dynamically set the source of the plugin? or is this for development mode?

I am also still unclear on why using the ref was not possible? Maybe needs expanding on how it affects the error boundary.. also that comment could be in the code, in case someone else comes and wonder why we didn't use ref here

@tomzemp
Copy link
Member Author

tomzemp commented Aug 28, 2023

out of curiosity, do we have a specific use-case here, where we need to dynamically set the source of the plugin? or is this for development mode?

Yeah. This situation occurs in the dashboard app because users can toggle between (for example) chart or map view of a visualization, which requires different plugin sources.

I am also still unclear on why using the ref was not possible?

I think the proposal was for recording whether communication was received with a ref, and currently I want the component to rerender (and have the useEffect be triggered) when communication received goes from true to false (this is being used to let user "try again" from an error state and indicate to the app that it needs to resend props to plugin). This could be refactored if it's confusing to use it for this purpose.

@tomzemp tomzemp merged commit cea7600 into alpha Sep 28, 2023
@tomzemp tomzemp deleted the LIBS-488/reset-iframe-src branch September 28, 2023 08:36
dhis2-bot added a commit that referenced this pull request Sep 28, 2023
# [3.10.0-alpha.5](v3.10.0-alpha.4...v3.10.0-alpha.5) (2023-09-28)

### Bug Fixes

* merge issues ([496472a](496472a))
* reset communication on either pluginSource or pluginShortName change ([3fdae5b](3fdae5b))
* trigger props resend when iframe src changes [LIBS-488] ([f4a6680](f4a6680))
* trigger props resend when iframe src changes [LIBS-488] [#1344](#1344) ([cea7600](cea7600))
@dhis2-bot
Copy link
Contributor

dhis2-bot added a commit that referenced this pull request Dec 21, 2023
# [3.11.0-alpha.1](v3.10.1...v3.11.0-alpha.1) (2023-12-21)

### Bug Fixes

* add back plugin service dependency [LIBS-583] ([ca10691](ca10691))
* add back plugin service dependency [LIBS-583] ([6d43ae3](6d43ae3))
* add documentation, clean up ([c537590](c537590))
* add in plugin service in runtime package ([#1343](#1343)) ([ed06a9f](ed06a9f))
* add width to plugin documentation [LIBS-487] ([b2c6273](b2c6273))
* check memomized props for postMessage communication [LIBS-514] ([b1a3a0a](b1a3a0a))
* clean up ([e53ecbd](e53ecbd))
* clean up, add useless test ([b14952b](b14952b))
* custom error handling ([c72fc6e](c72fc6e))
* dependency array ([03ce64f](03ce64f))
* dependency resolution ([2480c1c](2480c1c))
* merge issues ([496472a](496472a))
* move eslint disable line ([48912d7](48912d7))
* plugin experimental docs ([be215b2](be215b2))
* prevent sending updated props to plugin when props do not change [LIBS-514] ([86c6f75](86c6f75))
* reset communication on either pluginSource or pluginShortName change ([3fdae5b](3fdae5b))
* temporarily disable failing test ([6664199](6664199))
* trigger props resend when iframe src changes [LIBS-488] ([f4a6680](f4a6680))
* trigger props resend when iframe src changes [LIBS-488] [#1344](#1344) ([cea7600](cea7600))
* type error ([9c17206](9c17206))
* update alpha branch [skip release] ([ccb793c](ccb793c))
* working autorsize width ([2991045](2991045))

### Features

* add autoresizing for height ([dbb6e26](dbb6e26))
* experimental plugin release ([f5cca86](f5cca86))
* ideas for plugin wrappers [LIBS-397] ([be38607](be38607))
* implement plugin wrappers (alpha) ([#1332](#1332)) ([56a9a3f](56a9a3f))
* plugin experimental export ([25f02a6](25f02a6))
* plugin wrappers, errors + alerts ([bda6a43](bda6a43))
* update plugin wrappers ([30c963c](30c963c))
@dhis2-bot
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants