Skip to content

Ensure URL Metric is initially constructed with all elements prior to initializing extensions #1968

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

Merged
merged 1 commit into from
Apr 3, 2025

Conversation

westonruter
Copy link
Member

Summary

This is a follow-up to #1951.

When testing the plugin I noticed an error in the console:

Optimization Detective] Failed to initialize extension 'http://localhost:8888/wp-content/plugins/od-intrinsic-dimensions/detect.js?ver=0.2.0': Error: Unknown element with XPath: /HTML/BODY/DIV[@class='wp-site-blocks']/*[2][self::MAIN]/*[1][self::DIV]/*[3][self::DIV]/*[1][self::FIGURE]/*[1][self::VIDEO]
    at extendElementData (detect.js?ver=1.0.0-beta4:403:9)
    at captureIntrinsicDimensions (detect.js?ver=0.2.0:34:3)
    at Module.initialize (detect.js?ver=0.2.0:72:4)
    at detect (detect.js?ver=1.0.0-beta4:821:41)

The error coming from the Intrinsic Dimensions extension started occurring after westonruter/od-intrinsic-dimensions#4 where I updated it to use initialize instead of finalize since it was deprecated in #1951 in order to facilitate gzip compression in #1959. However, I realized that the location where extensions are initialized means that they cannot call extendElementData() because the URL Metric object has not been populated yet with its elements. This causes calls to extendElementData() to always fail if they are performed while the initialize() function is being called (and not after a delay, for example).

The fix is simply to move the extension initialization logic after the URL Metric data has been initially constructed with all of the tags (elements) being tracked.

@westonruter westonruter added [Type] Bug An existing feature is broken [Plugin] Optimization Detective Issues for the Optimization Detective plugin labels Apr 3, 2025
@westonruter westonruter requested a review from ShyamGadde April 3, 2025 21:20
@westonruter westonruter requested a review from felixarntz as a code owner April 3, 2025 21:20
@github-project-automation github-project-automation bot moved this to Not Started/Backlog 📆 in WP Performance 2025 Apr 3, 2025
@westonruter westonruter moved this from Not Started/Backlog 📆 to Code Review 👀 in WP Performance 2025 Apr 3, 2025
Copy link

github-actions bot commented Apr 3, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: westonruter <[email protected]>
Co-authored-by: ShyamGadde <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Contributor

@ShyamGadde ShyamGadde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense—thanks for catching this! LGTM.

@westonruter westonruter merged commit f550113 into trunk Apr 3, 2025
14 checks passed
@github-project-automation github-project-automation bot moved this from Code Review 👀 to Done 😃 in WP Performance 2025 Apr 3, 2025
@westonruter westonruter deleted the fix/od-extension-initialize-order branch April 3, 2025 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Bug An existing feature is broken
Projects
Status: Done 😃
Development

Successfully merging this pull request may close these issues.

2 participants