Skip to content
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(performance): cache isolatedHandle #12150

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/update-browser-pins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
node tools/update_chrome_revision.mjs
- name: Create Pull Request
if: ${{ steps.update.outputs.commit }}
uses: peter-evans/create-pull-request@70a41aba780001da0a30141984ae2a0c95d8704e # v6.0.2
uses: peter-evans/create-pull-request@c55203cfde3e5c11a452d352b4393e68b85b4533 # v6.0.3
with:
token: ${{ secrets.BROWSER_AUTOMATION_BOT_TOKEN }}
branch: browser-automation-bot/update-browser-version-chrome
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
node packages/browsers/tools/updateVersions.mjs
- name: Create Pull Request
if: ${{ steps.update.outputs.commit }}
uses: peter-evans/create-pull-request@70a41aba780001da0a30141984ae2a0c95d8704e # v6.0.2
uses: peter-evans/create-pull-request@c55203cfde3e5c11a452d352b4393e68b85b4533 # v6.0.3
with:
token: ${{ secrets.BROWSER_AUTOMATION_BOT_TOKEN }}
branch: browser-automation-bot/update-browser-version-firefox
Expand Down
16 changes: 15 additions & 1 deletion packages/puppeteer-core/src/api/ElementHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ export abstract class ElementHandle<
*/
declare [_isElementHandle]: boolean;

/**
* @internal
* Cached isolatedHandle to prevent
* trying to adopt it multiple times
*/
isolatedHandle?: typeof this;

/**
* A given method will have it's `this` replaced with an isolated version of
* `this` when decorated with this decorator.
Expand All @@ -163,7 +170,14 @@ export abstract class ElementHandle<
if (this.realm === this.frame.isolatedRealm()) {
return await target.call(this, ...args);
}
using adoptedThis = await this.frame.isolatedRealm().adoptHandle(this);
let adoptedThis: This;
if (this['isolatedHandle']) {
adoptedThis = this['isolatedHandle'];
} else {
this['isolatedHandle'] = adoptedThis = await this.frame
.isolatedRealm()
.adoptHandle(this);
}
const result = await target.call(adoptedThis, ...args);
// If the function returns `adoptedThis`, then we return `this`.
if (result === adoptedThis) {
Expand Down