Skip to content
Snippets Groups Projects
Unverified Commit 21ca26ac authored by Mehmet Salih Yavuz's avatar Mehmet Salih Yavuz Committed by GitHub
Browse files

fix(Row): don't unload charts while embedded to reduce rerenders (#33422)

parent 33e48146
Branches
No related tags found
No related merge requests found
...@@ -51,6 +51,7 @@ import WithPopoverMenu from 'src/dashboard/components/menu/WithPopoverMenu'; ...@@ -51,6 +51,7 @@ import WithPopoverMenu from 'src/dashboard/components/menu/WithPopoverMenu';
import { componentShape } from 'src/dashboard/util/propShapes'; import { componentShape } from 'src/dashboard/util/propShapes';
import backgroundStyleOptions from 'src/dashboard/util/backgroundStyleOptions'; import backgroundStyleOptions from 'src/dashboard/util/backgroundStyleOptions';
import { BACKGROUND_TRANSPARENT } from 'src/dashboard/util/constants'; import { BACKGROUND_TRANSPARENT } from 'src/dashboard/util/constants';
import { isEmbedded } from 'src/dashboard/util/isEmbedded';
import { EMPTY_CONTAINER_Z_INDEX } from 'src/dashboard/constants'; import { EMPTY_CONTAINER_Z_INDEX } from 'src/dashboard/constants';
import { isCurrentUserBot } from 'src/utils/isBot'; import { isCurrentUserBot } from 'src/utils/isBot';
import { useDebouncedEffect } from '../../../explore/exploreUtils'; import { useDebouncedEffect } from '../../../explore/exploreUtils';
...@@ -188,8 +189,11 @@ const Row = props => { ...@@ -188,8 +189,11 @@ const Row = props => {
observerDisabler = new IntersectionObserver( observerDisabler = new IntersectionObserver(
([entry]) => { ([entry]) => {
if (!entry.isIntersecting && isComponentVisibleRef.current) { if (!entry.isIntersecting && isComponentVisibleRef.current) {
// Reference: https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-rootmargin
if (!isEmbedded()) {
setIsInView(false); setIsInView(false);
} }
}
}, },
{ {
rootMargin: '400% 0px', rootMargin: '400% 0px',
......
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export const isEmbedded = () => {
try {
return window.self !== window.top || window.frameElement !== null;
} catch (e) {
return true;
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment