🐛 Register LINKER_CREATED on ampdoc instead of attribute#28268
🐛 Register LINKER_CREATED on ampdoc instead of attribute#28268zhouyx merged 5 commits intoampproject:masterfrom
LINKER_CREATED on ampdoc instead of attribute#28268Conversation
|
But we shouldn't be using attributes as markers. It seems we have a need to mark arbitrary data on the ampdoc instance ( |
Thanks! That's good to know. However based on #28220, the error appears very recently despite that the code was merged back in Feb.
I like the idea! Will generalize the solution. |
|
This is an async error being caught by a promise. If there's no Now, https://github.com/ampproject/amphtml/blame/c985e344b25effca5e8f2a604a3cef11eff6c0d3/extensions/amp-analytics/0.1/amp-analytics.js#L587 breaks the initialization out of the promise chain. It's now happening in chunked event loop. We have wrappers around these event loops that can catch the error and report it properly, even when the error comes from a non-anonymous script. So, I think the bug was always there, we just never received the reports. |
|
Oh, I remember this (#26683). Sorry, I like that you plan to abandon use of this attribute as a marker. If you need a quick fix in the meantime... |
|
Thank you @jridgewell That makes a lot of sense! |
|
Thank all for the suggestion. I've introduced a more generic solution as Justin suggested. |
src/service/ampdoc-impl.js
Outdated
| * Attempt to register a service that is allowed/required one for each ampdoc. | ||
| * Caller need to handle user error when registration returns false. | ||
| * | ||
| * Please list your service name below: |
There was a problem hiding this comment.
I don't want to add extra bytes to the runtime by keeping an enum list. But I do want to keep such a list somewhere for reference so that we don't end up with identical service name. Let me know if there's better way to address : )
There was a problem hiding this comment.
Enums get eliminated if unused, and the Enum.FOO reference will be rewritten with whatever the value is if it's used. Enums are basically 0 cost. 😉
There was a problem hiding this comment.
That's cool! Switched to enum
jridgewell
left a comment
There was a problem hiding this comment.
Thanks for cleaning this up!
| ); | ||
|
|
||
| if (linkerCreatedEl.hasAttribute(LINKER_CREATED)) { | ||
| if (!this.ampdoc_.registerService(LINKER_CREATED)) { |
There was a problem hiding this comment.
Nit: Just return this.ampdoc_.registerService(LINKER_CREATED)?
src/service/ampdoc-impl.js
Outdated
| * Attempt to register a service that is allowed/required one for each ampdoc. | ||
| * Caller need to handle user error when registration returns false. | ||
| * | ||
| * Please list your service name below: |
There was a problem hiding this comment.
Enums get eliminated if unused, and the Enum.FOO reference will be rewritten with whatever the value is if it's used. Enums are basically 0 cost. 😉
src/service/ampdoc-impl.js
Outdated
| registerTrackingIframe() { | ||
| if (this.hasTrackingIframe_) { | ||
| return false; | ||
| registerService(name) { |
There was a problem hiding this comment.
Nit: I wouldn't call this service, to avoid confusion with ampdoc/window services. Maybe "singleton"?
There was a problem hiding this comment.
Sounds good. Changed to registerSingleton()
| * limitations under the License. | ||
| */ | ||
|
|
||
| import {AMPDOC_SINGLETON_NAME} from '../../../src/service/ampdoc-impl'; |
There was a problem hiding this comment.
Maybe we should move this elsewhere, with only this in the file? That way there are no transitive imports, and we don't need the presubmit whitelist?
There was a problem hiding this comment.
I agreed! Any idea where to move it to. I wish there's a src/const.js file.
There was a problem hiding this comment.
That sounds fine to me. Or src/enums.js
LINKER_CREATED attribute to ampdoc.bodyLINKER_CREATED on ampdoc instead of attribute
| * Registred singleton on AMP doc. | ||
| * @enum {number} | ||
| */ | ||
| export const AMPDOC_SINGLETON_NAME = { |
There was a problem hiding this comment.
How about just AMPDOC_SINGLETON?
| */ | ||
|
|
||
| /** | ||
| * Registred singleton on AMP doc. |
There was a problem hiding this comment.
Registered singleton on AmpDoc.
To fix #28220.
TBH I still don't know what's causing the error. But the purpose of the check is to only initiate the linker manager once for each ampdoc. No need to check for
ShadowRoot, the attribute can be applied to the document.body.