forked from ampproject/amphtml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Fix race condition with layout -> unlayout (ampproject#30426)
* Fix race condition with layout -> unlayout When an unlayout (eg, when carousel swipes away) occurs before an unlayout, we can get into a broken state where we _think_ we're fully laid out but in reality we've performed the unlayout. There's still race conditions in each component, since they need to track their own layout/unlayout state. We should quickly migrate to Bento where this isn't an issue. Fixes ampproject#27036 Partial ampproject#13838 * Rename variable * Throw cancellation errors where appropriate * Review fixes * Fix dep requirement * Fix sourcemap check * Fix tests * Only allow missing signal param in test mode * Do not report missing abortController Since we're clearing it out after layout completes, it won't exist when we eventually unlayout * Toggle amp-analytics visibility _after_ layout * Fix method call * Fix test * lint * Fix test
- Loading branch information
1 parent
9a6fe63
commit ef68ca9
Showing
10 changed files
with
220 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
class AbortController { | ||
/** */ | ||
constructor() { | ||
/** @const {!AbortSignal} */ | ||
this.signal_ = new AbortSignal(); | ||
} | ||
|
||
/** */ | ||
abort() { | ||
this.signal_.isAborted_ = true; | ||
} | ||
|
||
/** | ||
* @return {!AbortSignal} | ||
*/ | ||
get signal() { | ||
return this.signal_; | ||
} | ||
} | ||
|
||
class AbortSignal { | ||
/** */ | ||
constructor() { | ||
/** @private {boolean} */ | ||
this.isAborted_ = false; | ||
} | ||
|
||
/** | ||
* @return {boolean} | ||
*/ | ||
get aborted() { | ||
return this.isAborted_; | ||
} | ||
} | ||
|
||
/** | ||
* @param {!Window} win | ||
*/ | ||
export function install(win) { | ||
if (win.AbortController) { | ||
return; | ||
} | ||
Object.defineProperty(win, 'AbortController', { | ||
configurable: true, | ||
enumerable: false, | ||
writable: true, | ||
value: AbortController, | ||
}); | ||
Object.defineProperty(win, 'AbortSignal', { | ||
configurable: true, | ||
enumerable: false, | ||
writable: true, | ||
value: AbortSignal, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.