From 6f5f77fa4fb925a35c1ec4509c2301362b5b621e Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Fri, 8 May 2020 11:53:48 +0000 Subject: [PATCH] Bug 1611096 - Add test for inspector target switching r=ochameau,rcaliman Depends on D62622 Differential Revision: https://phabricator.services.mozilla.com/D62623 --- devtools/client/fronts/walker.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/devtools/client/fronts/walker.js b/devtools/client/fronts/walker.js index ed5d0abe3f37..928e36da4ad6 100644 --- a/devtools/client/fronts/walker.js +++ b/devtools/client/fronts/walker.js @@ -61,10 +61,25 @@ class WalkerFront extends FrontClassWithSpec(walkerSpec) { * set. */ async getRootNode() { - if (this.rootNode) { - return this.rootNode; + // We automatically start and stop watching when getRootNode is called so + // that consumers using getRootNode without watchRootNode can still get a + // correct rootNode. Otherwise they might receive an outdated node. + // See https://bugzilla.mozilla.org/show_bug.cgi?id=1633348. + this._rootNodeWatchers++; + if (this.traits.watchRootNode && this._rootNodeWatchers === 1) { + await super.watchRootNode(); } - const rootNode = await this.once("root-available"); + + let rootNode = this.rootNode; + if (!rootNode) { + rootNode = await this.once("root-available"); + } + + this._rootNodeWatchers--; + if (this.traits.watchRootNode && this._rootNodeWatchers === 0) { + super.unwatchRootNode(); + } + return rootNode; }