Forum Discussion

midhun_e's avatar
midhun_e
Cloud Apps
07-01-2025

How to prevent iframe reload when switching tabs in React app embedding Sisense dashboard?

Hi everyone,

I'm embedding a Sisense dashboard using an iframe inside a React-based platform. The iframe is rendered on a dedicated Insights tab route: insights. Every time I switch away from this tab and return to it, the iframe reloads, which causes unnecessary load time and loss of dashboard state (like applied filters or selections).

My goal is to mount the iframe only once, keep it cached in memory, and just hide/show it based on tab switching, without triggering a reload.

Here’s what I’m trying to achieve:

Mount the Sisense iframe only once (on first visit to /insights)

Persist it in memory even when navigating away

Show it again without reloading when coming back

Has anyone implemented this pattern or has best practices around iframe caching or persistent embedding of dashboards in a React environment?

Would love to hear suggestions or recommended approaches from the community!

Thanks!

5 Replies

  • JeremyFriedel's avatar
    JeremyFriedel
    Sisense Employee

    Hi Midhun_e,

    I don't believe this exact question has been asked before, but there are some related approaches that may be helpful.

    In general, it sounds like the iframe reload can be avoided by preserving the DOM element and simply toggling its visibility, rather than unmounting it during navigation.

     

    One effective method is to use a higher-level component to manage the iframe's state, rendering it once and conditionally showing or hiding it based on route or tab state:

    // IframeContainer.js general example
    import React, { useRef, useEffect } from 'react';
    
    const IframeContainer = ({ isVisible }) => {
      const iframeRef = useRef(null);
    
      useEffect(() => {
        if (!iframeRef.current) {
          iframeRef.current = document.createElement('iframe');
          iframeRef.current.src = 'https://sisenseUrl.sisense.com';
          iframeRef.current.style.width = '100%';
          iframeRef.current.style.height = '100%';
          iframeRef.current.id = 'sisense-dashboard';
          document.getElementById('iframe-wrapper').appendChild(iframeRef.current);
        }
        iframeRef.current.style.display = isVisible ? 'block' : 'none';
      }, [isVisible]);
    
      return <div id="iframe-wrapper" style={{ width: '100%', height: '100%' }} />;
    };
    
    export default IframeContainer;
    

    This component can be used with code such as this

    <IframeContainer isVisible={currentTab === 'insights'} />
    



     

    Alternatively, you can render the iframe once in a hidden container outside of the main routing view, and then control its visibility using CSS or React state. This ensures that the iframe remains mounted in the DOM across route changes:

     

    <div id="persisted-iframes">
      <iframe
        id="sisense-dashboard"
        src="https://sisenseUrl.sisense.com"
        style={{ display: currentTab === 'insights' ? 'block' : 'none' }}
      />
    </div>
    

    Both these examples can be modified to fit your application.

     

    As a much broader change, ComposeSDK can be used to "natively" use React code within your application to display Sisense widgets and dashboards, it is designed to natively integrate into a React application with React based code, without having to use iframes.

    • midhun_e's avatar
      midhun_e
      Cloud Apps

      But compose sdk restricts the integrity of widgets among them right? it makes widgets independent from one another. Like drill-down feature, ux feel all are compromised in compose sdk. So anyway to achieve this?

      • JeremyFriedel's avatar
        JeremyFriedel
        Sisense Employee

        ComposeSDK does allow widgets to share filters, this is defined directly in the ComposeSDK code, the same filter object can be used for multiple widgets.

        An example of this functionality is located here.

  • Hello midhun_e​,

    I’m following up to see if the solution offered by JeremyFriedel​ worked for you.

    If so, please click the 'Accept as Solution' button on the appropriate post. That way others with the same questions can find the answer. If not, please let us know so that we can continue to help.

    Thank you.