Skip to content

Commit

Permalink
fix: prevent re-rendering/flashing of maps and charts [DHIS2-14979] […
Browse files Browse the repository at this point in the history
…v40] (#2266)

* fix: unwanted re-rendering of dashboard items (#2247)

* fix: solve most unwanted re-renders of dashboard items

This is basically reverting a change I added to solve a DV Highchart's
cutoff issue.
I think I found another approach for that issue which does not require
to pass style to the plugin, which is a problem because of course it
changes any time the dashboard item container changes size (window
resize, resize of other dashboard items, interpretation panel toggle,
etc...).

* chore: bump cli-app-scripts to solve no-service-worker issue

* fix: avoid sending props twice when using View as and plugin changes (#2248)

* fix: use chrome in e2e tests

---------

Co-authored-by: Edoardo Sabadelli <edoardo@dhis2.org>
  • Loading branch information
jenniferarnesen and edoardo authored Mar 22, 2023
1 parent 9cf62d6 commit dbd7cb8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,19 @@ jobs:
runs-on: ubuntu-latest
needs: install
if: "!contains(github.event.head_commit.message, '[skip ci]')"
container:
image: cypress/browsers:node16.17.0-chrome106
options: --user 1001

strategy:
matrix:
containers: [1, 2]

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- uses: actions/setup-node@v1
- uses: actions/setup-node@v3
with:
node-version: 14.x

Expand All @@ -131,13 +134,14 @@ jobs:
run: yarn cypress install

- name: End-to-End tests
uses: cypress-io/github-action@v2
uses: cypress-io/github-action@v5
with:
record: true
parallel: true
start: ${{ env.SERVER_START_CMD }}
wait-on: ${{ env.SERVER_URL }}
wait-on-timeout: 300
browser: chrome
cache-key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
group: 'e2e'
tag: ${{ github.event_name }}
Expand Down
42 changes: 22 additions & 20 deletions src/components/Item/VisualizationItem/Visualization/IframePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const IframePlugin = ({

// When this mounts, check if the dashboard is recording
const { isCached, recordingState } = useCacheableSection(dashboardId)
const [communicationReceived, setCommunicationReceived] = useState(false)
const [recordOnNextLoad, setRecordOnNextLoad] = useState(
recordingState === 'recording'
)
Expand All @@ -47,7 +48,6 @@ const IframePlugin = ({
forDashboard: true,
displayProperty: userSettings.displayProperty,
visualization,
style,
onError,

// For caching: ---
Expand All @@ -65,7 +65,6 @@ const IframePlugin = ({
itemId,
isCached,
recordOnNextLoad,
style,
]
)

Expand All @@ -88,34 +87,37 @@ const IframePlugin = ({

useEffect(() => {
if (iframeRef?.current) {
const listener = postRobot.on(
'getProps',
// listen for messages coming only from the iframe rendered by this component
{ window: iframeRef.current.contentWindow },
() => {
if (recordOnNextLoad) {
// Avoid recording unnecessarily,
// e.g. if plugin re-requests props for some reason
setRecordOnNextLoad(false)
// if iframe has not sent initial request, set up a listener
if (!communicationReceived) {
const listener = postRobot.on(
'getProps',
// listen for messages coming only from the iframe rendered by this component
{ window: iframeRef.current.contentWindow },
() => {
setCommunicationReceived(true)

if (recordOnNextLoad) {
// Avoid recording unnecessarily,
// e.g. if plugin re-requests props for some reason
setRecordOnNextLoad(false)
}

return pluginProps
}
)

return pluginProps
}
)

return () => listener.cancel()
return () => listener.cancel()
}
}
}, [recordOnNextLoad, pluginProps])

useEffect(() => {
if (iframeRef.current?.contentWindow) {
if (communicationReceived && iframeRef.current?.contentWindow) {
postRobot.send(
iframeRef.current.contentWindow,
'newProps',
pluginProps
)
}
}, [pluginProps])
}, [communicationReceived, recordOnNextLoad, pluginProps])

useEffect(() => {
setError(null)
Expand Down

0 comments on commit dbd7cb8

Please sign in to comment.