Context
I am implementing embedded QuickSight analytics in my Next.js 14 application using the App Router. I have multiple dashboards, each containing several sheets. My goal is to provide a seamless user experience where each page in my app displays only one specific sheet, without the default QuickSight navigation bar, only the sheet content should be visible.
I am using the “Create Embed URL for Registered User” approach to generate the embedded QuickSight URLs.
Problem
On navigating between pages, the embedded QuickSight URL becomes invalid. It seems that since Next.js unmounts the iframe during navigation, the embedded session is lost, and the URL cannot be reused. This forces me to fetch a new embed URL every time the user navigates to a different page, which negatively impacts the user experience.
Questions :
- Is this expected behavior?
Given the way Next.js and React handle component unmounting, is this behavior something inherent to the framework’s lifecycle? - Does the QuickSight SDK provide a way to persist the session across page navigations?
I explored different solutions but couldn’t find a straightforward way to retain the embed URL across navigations. - Potential Solutions:
3.1 One approach I am considering is using a React portal to keep the iframe mounted globally and only update its content.
3.2 Another option is rendering all dashboards within the main layout and showing/hiding them instead of remounting on every navigation.
3.3 Are there any best practices or recommended patterns for handling embedded QuickSight in Next.js?
I want to ensure that this is an expected limitation of how Next.js (App Router) and React handle component lifecycles rather than an issue in my implementation. Any insights or alternative solutions would be greatly appreciated!