Skip to content

SCAL-349561 Fixed Render a new iframe when replaceExistingPreRender is true - #772

Open
shivam-kumar-ts wants to merge 7 commits into
mainfrom
SCAL-349561
Open

shivam-kumar-ts wants to merge 7 commits into
mainfrom
SCAL-349561

Conversation

@shivam-kumar-ts

@shivam-kumar-ts shivam-kumar-ts commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

The problem

A pre-render is a hidden iframe that loads a Liveboard in the background, so it opens instantly later.

The app pre-renders Liveboard A. Later it says: "throw that away and pre-render Liveboard B instead". That's what preRender(false, true) means; the second true is replaceExistingPreRender.

But the hidden frame kept showing A.

What I changed

In preRender(), when a pre-render already exists and replaceExistingPreRender is true, the SDK now cleans up first with a new step, discardExistingPreRender():

  1. Tells the old instance (A) to stop listening. A no longer reacts to messages from a frame it doesn't own anymore.
  2. Removes the old hidden box and iframe from the page (preRenderController.discard()), and forgets about them.
  3. Forgets the old iframe (this.iFrame = undefined) and marks itself as not rendered yet.

Then the normal render runs. It finds no iframe, so it creates a brand-new one from B's config, and B loads.

@shivam-kumar-ts
shivam-kumar-ts requested a review from a team as a code owner November 24, 2026 08:37

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements the ability to discard and replace an existing pre-rendered embed when replaceExistingPreRender is set to true. It introduces a discard method in PreRenderController to destroy and clear the wrapper and child elements, and a discardExistingPreRender helper in TsEmbed to clean up event listeners and reset state. Corresponding unit tests have been added to verify that the old iframe is disconnected and a new one is successfully rendered. There are no review comments to address, and the changes look solid.

@pkg-pr-new

pkg-pr-new Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@thoughtspot/visual-embed-sdk@772

commit: c7cec35

@shivam-kumar-ts

Copy link
Copy Markdown
Contributor Author

@gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a mechanism to discard and replace an existing pre-rendered embed instance when replaceExistingPreRender is enabled. It adds a discard method to PreRenderController to clean up elements and implements discardExistingPreRender in TsEmbed to unsubscribe the previous owner and reset the iframe. The feedback suggests a critical improvement: ensuring that the previousOwner's iFrame and isRendered properties are also reset to prevent memory leaks or errors if the old instance is accessed later. Additionally, the reviewer recommends updating the unit tests to assert that this state cleanup is performed correctly.

Comment thread src/embed/ts-embed.ts Resolved
Comment thread src/embed/ts-embed.spec.ts Resolved
Comment thread src/embed/liveboard.spec.ts Resolved
@shivam-kumar-ts

Copy link
Copy Markdown
Contributor Author

@gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ability to discard and replace an existing pre-rendered iframe when replaceExistingPreRender is enabled, adding cleanup logic in both TsEmbed and PreRenderController along with corresponding unit tests. The review feedback correctly identifies an opportunity to prevent memory leaks by ensuring event listeners are cleaned up even when the previous owner is the current instance, and suggests updating setIframeElement to accept undefined to prevent TypeScript compilation errors.

Comment thread src/embed/ts-embed.ts Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant