cdc-open-viz icon indicating copy to clipboard operation
cdc-open-viz copied to clipboard

dev-9150 Fix double data requests for charts and maps

Open jayb opened this issue 1 year ago • 0 comments

When charts or maps are embedded like <CdcChart configUrl=, they make one data request on page load, but when they're embedded like <CdcChart config=, they make two. Since they're embedded with configUrl= when viewing charts locally but with config= in WCMS, we only see the issue on live charts.

This useEffect (which is only added when loading the chart with a configObj) is what's causing the double-request. I think the original intent of the useEffect was for dashboard filtering, but it's a little hard to tell if this change will have other side effects.

To test that this fixes the issue, chart/src/index.jsx can be changed to:

import React from 'react'
import ReactDOM from 'react-dom/client'

import CdcChart from './CdcChart'

import 'react-tooltip/dist/react-tooltip.css'

let isEditor = window.location.href.includes('editor=true')
let isDebug = window.location.href.includes('debug=true')

let domContainer = document.getElementsByClassName('react-container')[0]

let configUrl = domContainer.attributes['data-config'].value;
let config = (await (await fetch(configUrl)).json());

ReactDOM.createRoot(domContainer).render(
  <CdcChart config={config} isEditor={isEditor} isDebug={isDebug} />
  //<CdcChart configUrl={configUrl} isEditor={isEditor} isDebug={isDebug} />
)

jayb avatar Sep 10 '24 13:09 jayb