-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: don't reload OOPIFs #1273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: don't reload OOPIFs #1273
Conversation
🦋 Changeset detectedLatest commit: bc88104 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 files reviewed, 3 comments
Greptile OverviewGreptile SummaryThis PR replaces wasteful OOPIF reload logic with an elegant clone-and-replace approach for shadow root piercing. Previously, when the shadow root piercer was injected after custom elements had already created their shadow roots, the code would reload entire iframes to trigger re-creation. The new approach walks the DOM, identifies custom elements missing tracked shadow roots, and clones/replaces them to trigger the Key Changes
AnalysisThe implementation is well-designed with proper error handling at multiple levels (try-catch in rerender loop, catch blocks on CDP calls). The clone-and-replace approach is more predictable than page reloads and avoids race conditions. The only edge case is custom elements that create shadow roots in constructors before connection, which is already discouraged by web component best practices. Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Browser as Chrome/Browser
participant CDP as CDP Session
participant Context as V3Context
participant Piercer as installV3PiercerIntoSession
participant Document as OOPIF Document
participant CustomEl as Custom Elements
Browser->>CDP: Target.attachedToTarget (OOPIF)
CDP->>Context: onAttachedToTarget()
Context->>Context: executionContexts.attachSession()
Context->>Piercer: ensurePiercer(session)
Note over Piercer: Install shadow root piercer
Piercer->>Document: Page.addScriptToEvaluateOnNewDocument(v3ScriptContent)
Piercer->>Document: Runtime.evaluate(v3ScriptContent)
Note over Document: attachShadow() now patched
Note over Piercer: Run rerender script
Piercer->>Document: Runtime.evaluate(reRenderScriptContent)
Document->>Document: createTreeWalker() - find custom elements
Document->>Document: filter elements with missing shadow roots
loop For each missing shadow root
Document->>CustomEl: cloneNode(true)
Document->>CustomEl: replaceWith(clone)
CustomEl->>CustomEl: connectedCallback() triggered
CustomEl->>Document: attachShadow() [PATCHED]
Note over Document: Shadow root now tracked!
end
Piercer-->>Context: return true (success)
Context->>Context: Continue OOPIF initialization
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5 files reviewed, no comments
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @browserbasehq/[email protected] ### Patch Changes - [#1273](#1273) [`ab51232`](ab51232) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: trigger shadow root rerender in OOPIFs by cloning & replacing instead of reloading - [#1268](#1268) [`c76ade0`](c76ade0) Thanks [@tkattkat](https://github.com/tkattkat)! - Expose reasoning, and cached input tokens in stagehand metrics - [#1267](#1267) [`ffb5e5d`](ffb5e5d) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: file uploads failing on Browserbase - [#1269](#1269) [`772e735`](772e735) Thanks [@tkattkat](https://github.com/tkattkat)! - Add example using playwright screen recording ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies \[[`ab51232`](ab51232), [`c76ade0`](c76ade0), [`ffb5e5d`](ffb5e5d), [`772e735`](772e735)]: - @browserbasehq/[email protected] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
madcio-rgb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
T
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @browserbasehq/[email protected] ### Patch Changes - [#1273](browserbase/stagehand#1273) [`ab51232`](browserbase/stagehand@ab51232) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: trigger shadow root rerender in OOPIFs by cloning & replacing instead of reloading - [#1268](browserbase/stagehand#1268) [`c76ade0`](browserbase/stagehand@c76ade0) Thanks [@tkattkat](https://github.com/tkattkat)! - Expose reasoning, and cached input tokens in stagehand metrics - [#1267](browserbase/stagehand#1267) [`ffb5e5d`](browserbase/stagehand@ffb5e5d) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: file uploads failing on Browserbase - [#1269](browserbase/stagehand#1269) [`772e735`](browserbase/stagehand@772e735) Thanks [@tkattkat](https://github.com/tkattkat)! - Add example using playwright screen recording ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies \[[`ab51232`](browserbase/stagehand@ab51232), [`c76ade0`](browserbase/stagehand@c76ade0), [`ffb5e5d`](browserbase/stagehand@ffb5e5d), [`772e735`](browserbase/stagehand@772e735)]: - @browserbasehq/[email protected] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
why
attachShadow()callwhat changed
attachShadow()functiontest plan