Skip to content

Enforce appended script ordering#18559

Open
timkelty wants to merge 5 commits into4.xfrom
bugfix/enforce-sync-js
Open

Enforce appended script ordering#18559
timkelty wants to merge 5 commits into4.xfrom
bugfix/enforce-sync-js

Conversation

@timkelty
Copy link
Copy Markdown
Contributor

@timkelty timkelty commented Mar 13, 2026

Summary

  • Load appended scripts in order via native script insertion.
  • Queue appendHeadHtml() / appendBodyHtml() so existing non-awaited call sites still complete in order.
  • Remove the unused app/resource-js fallback and endpoint.

Reproduce

On any CP page, run:

delete window.__appendTest;

Craft.appendBodyHtml(
  '<script src="https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js"><\/script>'
);

Craft.appendBodyHtml(
  '<script>window.__appendTest = typeof dayjs; console.log("append test:", window.__appendTest);<\/script>'
);

Before this fix, the second call can log undefined. With this fix, it should log function.

To verify the shared queue:

delete window.__headBodyTest;

Craft.appendHeadHtml(
  '<script src="https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js"><\/script>'
);

Craft.appendBodyHtml(
  '<script>window.__headBodyTest = typeof dayjs; console.log("head/body test:", window.__headBodyTest);<\/script>'
);

With this fix, it should log function.

Background

The earlier app/resource-js fallback was introduced in 1a958a7. It could appear to help because it converted cross-domain CP resource URLs into same-origin requests, keeping jQuery on its same-origin script-loading path. But the append flow still relied on jQuery's script handling, so dependent appended scripts were not guaranteed to execute in order.

Relevant jQuery issues:

@timkelty timkelty marked this pull request as ready for review April 3, 2026 03:51
@timkelty timkelty requested a review from brandonkelly April 3, 2026 03:51
@timkelty timkelty changed the title Enforce sync JS Enforce appended script ordering Apr 3, 2026
@timkelty timkelty requested a review from brianjhanson April 3, 2026 03:57
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.

1 participant