Skip to content

Commit

Permalink
Replace sliceFormData with the initial form data
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje committed May 11, 2022
1 parent ed6e5f9 commit 33690f9
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ function ExploreViewContainer(props) {
const theme = useTheme();

const isBeforeUnloadActive = useRef(false);
const initialFormData = useRef(props.form_data);

const defaultSidebarsWidth = {
controls_width: 320,
Expand Down Expand Up @@ -384,7 +385,7 @@ function ExploreViewContainer(props) {

useEffect(() => {
const formDataChanged = !isEmpty(
getFormDataDiffs(props.chart.sliceFormData, props.form_data),
getFormDataDiffs(initialFormData.current, props.form_data),
);
if (formDataChanged && !isBeforeUnloadActive.current) {
window.addEventListener('beforeunload', handleUnloadEvent);
Expand All @@ -394,7 +395,7 @@ function ExploreViewContainer(props) {
window.removeEventListener('beforeunload', handleUnloadEvent);
isBeforeUnloadActive.current = false;
}
}, [props.chart.sliceFormData, props.form_data]);
}, [props.form_data]);

// cleanup beforeunload event listener
// we use separate useEffect to call it only on component unmount instead of on every form data change
Expand Down

0 comments on commit 33690f9

Please sign in to comment.