From 21ca26acd72bde50cb75c3daa8ba328054944f6f Mon Sep 17 00:00:00 2001 From: Mehmet Salih Yavuz <salih.yavuz@proton.me> Date: Tue, 13 May 2025 16:32:39 +0300 Subject: [PATCH] fix(Row): don't unload charts while embedded to reduce rerenders (#33422) --- .../components/gridComponents/Row.jsx | 6 ++++- .../src/dashboard/util/isEmbedded.ts | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 superset-frontend/src/dashboard/util/isEmbedded.ts diff --git a/superset-frontend/src/dashboard/components/gridComponents/Row.jsx b/superset-frontend/src/dashboard/components/gridComponents/Row.jsx index a353d85c3b..1025e4101d 100644 --- a/superset-frontend/src/dashboard/components/gridComponents/Row.jsx +++ b/superset-frontend/src/dashboard/components/gridComponents/Row.jsx @@ -51,6 +51,7 @@ import WithPopoverMenu from 'src/dashboard/components/menu/WithPopoverMenu'; import { componentShape } from 'src/dashboard/util/propShapes'; import backgroundStyleOptions from 'src/dashboard/util/backgroundStyleOptions'; 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 { isCurrentUserBot } from 'src/utils/isBot'; import { useDebouncedEffect } from '../../../explore/exploreUtils'; @@ -188,7 +189,10 @@ const Row = props => { observerDisabler = new IntersectionObserver( ([entry]) => { if (!entry.isIntersecting && isComponentVisibleRef.current) { - setIsInView(false); + // Reference: https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-rootmargin + if (!isEmbedded()) { + setIsInView(false); + } } }, { diff --git a/superset-frontend/src/dashboard/util/isEmbedded.ts b/superset-frontend/src/dashboard/util/isEmbedded.ts new file mode 100644 index 0000000000..3c8d30fcce --- /dev/null +++ b/superset-frontend/src/dashboard/util/isEmbedded.ts @@ -0,0 +1,26 @@ +/** + * 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; + } +}; -- GitLab