Skip to content

Fixed attach cloud library listeners early - #1241

Open
girishpanchal30 wants to merge 4 commits into
developmentfrom
bugfix/1211
Open

girishpanchal30 wants to merge 4 commits into
developmentfrom
bugfix/1211

Conversation

@girishpanchal30

Copy link
Copy Markdown
Contributor

All Submissions:

Changes proposed in this Pull Request:

The Cloud Library page could stay on "Loading..." forever. admin-page.js was loaded in the footer, so on heavy admin pages the DAM iframe could finish loading and send getUrl before the script attached its listeners. Both events were missed.

  • Load admin-page.js in the head, so the listeners are attached before the iframe exists.
  • Listen for the iframe load event on document in the capture phase, and look up #om-dam when getUrl arrives.
  • Render the loader before the iframe, so it already exists if the iframe loads immediately.

The Media Library modal is not affected. The retry/timeout in Dam.vue belongs to optimole-service and is not part of this PR.

Closes #1211.

How to test the changes in this Pull Request:

  1. On a site with many active admin plugins (e.g. Elementor, Yoast, WPForms, SearchWP), open Optimole → Cloud Library.
  2. In Chrome DevTools, set CPU throttling to 6x and reload the page several times.
  3. Before: some loads stay on the Optimole logo with "Loading...". After: the Cloud Library grid appears on every reload.
  4. Insert an image from the Optimole tab in the Media Library modal and confirm it still works.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@pirate-bot

pirate-bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Plugin build for b516245 is ready 🛎️!

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟢 Approved

The Cloud Library script now loads in the head, and both iframe events are handled in a real browser.

Validation details
  • Files reviewed: 4/4 changed files.
  • The rendered Cloud Library page prints admin-page.js in the head, before the loader and the iframe (WordPress sandbox, PHP 8.3.36) [R11][R12].
  • In Chromium, a stubbed DAM iframe sent getUrl at once. The loader hid, the iframe showed, and the iframe got siteUrl. The console showed no errors.
  • The Jest test passed at HEAD cd /repo && set -o pipefail; timeout 280 npx jest assets/src/media/__tests__/admin-page.test.js --verbose 2>&1 | tee /wo… (run R2, exit 0). At pr-base it failed on load, not on an assertion set -o pipefail; B=/workspace/checks/C6/base-jest; rm -rf $B; mkdir -p $B && cd /repo && git archive 3402c1e | tar -x -C… (run R3, exit 0).
  • The PHPUnit test passed at HEAD cd /repo && set -o pipefail; timeout 280 vendor/bin/phpunit --do-not-cache-result -c phpunit.xml --filter 'Test_Dam::tes… (run R8, exit 0). At pr-base it failed on the footer group assertion set -o pipefail; cd /repo && B=/workspace/checks/C6/base-php; rm -rf $B; mkdir -p $B && git archive 3402c1e | tar -x -C … (run R9, exit 1).
  • The build output is git-ignored and is built at release, so no stale bundle ships git grep -n -E 'assets/build|wp-scripts|npm run|dist|build' HEAD -- .gitignore .distignore package.json .github/workflow… (run R7, exit 0).
Untested areas
  • The real Optimole DAM app was stubbed in the browser check.
  • Image insertion from the Media Library modal was not exercised in a browser.
  • The variant pass did not settle these places, where the fixed cause may still reach:
    • assets/src/media/modal/messageHandler.js:42-67,84-91 — unverified: Both Select and Post modals defer the message listener until iframe load: "window.addEventListener( 'message', self.messageListener )" is inside that callback. A getUrl delivered e…
    • assets/src/media/media-modal.js:11-15 — unverified: Both Select and Post modals defer the message listener until iframe load: "window.addEventListener( 'message', self.messageListener )" is inside that callback. A getUrl delivered e…

🤖 Automated review · run code-review-agent_6afaf0d3b875f2.87831781.


🤖 Review agent — review posted ✅ on 3402c1e4 · approved · 0 findings · 13 min

Run code-review-agent_6afaf0d3b875f2.87831781 · trail

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟢 Approved

This approves the test update since the last review, and the note asks for one Elementor Image Box check.

Validation details
  • Files reviewed: 4/4 changed files. Only tests/test-dam.php changed since the prior review.
  • The new PHPUnit test passed at HEAD without built assets set -o pipefail; P=/var/www/html/wp-content/plugins/optimole-wp; H=/tmp/C1-head; cd /repo; git worktree add --quiet --de… printed OK (1 test, 3 assertions) (run R2).
  • The whole Test_Dam class passed at HEAD set -o pipefail; P=/var/www/html/wp-content/plugins/optimole-wp; H=/tmp/C1-head; cd /repo; git worktree add --quiet --de… printed OK (12 tests, 138 assertions) (run R2).
  • The test failed at pr-base on the order assertion set -o pipefail; P=/var/www/html/wp-content/plugins/optimole-wp; cd /tmp/C1-base; ln -sfn /tmp/C1-base $P && ls -la $P; … printed Failed asserting that 345 is less than 108. (run R1).
  • Source and browser checks of run code-review-agent_6afaf0d3b875f2.87831781 were reused, not rerun. The source is unchanged since then.
Untested areas
  • No PHPUnit test covers the head enqueue. It needs a built asset file that CI does not build.
  • The variant pass and requirements check were not rerun. The Media Library modal listener stays unverified.
  • Issue #828 (closed): Fatal Error with "Image Box" Widget Using Optimole DAM in Elementor. It was not exercised in a browser.

🤖 Automated review · run code-review-agent_6afaf8c84da032.24086749.


🤖 Review agent — review posted ✅ on b516245b · approved · 0 findings · 9 min

Run code-review-agent_6afaf8c84da032.24086749 · trail

Comment thread inc/dam.php
Comment on lines 429 to +437
display: none !important;
}
</style>
<iframe id="om-dam" style="display: none;" src="<?php echo( $this->build_iframe_url() ); ?>" allow="clipboard-read; clipboard-write"></iframe>
<div class="om-dam-loader">
<img src="<?php echo esc_url( OPTML_URL . 'assets/img/logo.png' ); ?>" alt="Optimole Logo"
class="om-dam-logo">
<p><?php echo esc_html__( 'Loading', 'optimole-wp' ); ?>...</p>
</div>
<iframe id="om-dam" style="display: none;" src="<?php echo( $this->build_iframe_url() ); ?>" allow="clipboard-read; clipboard-write"></iframe>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

note The DAM markup this change reorders is also printed inside the media modal template, which Elementor's editor loads. Issue #828 crashed when a Cloud Library image was picked for the Elementor "Image Box" widget. The fix for that lookup is untouched. Please pick a Cloud Library image in an Image Box widget once. Safe: the widget renders the image. Broken: the editor shows a TypeError or a fatal error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloud Library stuck on "Loading" when iframe loads before admin-page.js

2 participants