Skip to content

Commit

Permalink
fix: Evaluate assets in sequence (#26208)
Browse files Browse the repository at this point in the history
Fetching can be done in parallel and out of order but execution should
depend on order specified in args otherwise it breaks things like
calander which has 2 JS file and 2nd one depends on first one.
  • Loading branch information
ankush committed Apr 29, 2024
1 parent e4ed1b9 commit a7b7af8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions frappe/public/js/frappe/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class AssetManager {
const version_string =
frappe.boot.developer_mode || window.dev_server ? Date.now() : window._version_number;

let fetched_assets = {};
async function fetch_item(path) {
// Add the version to the URL to bust the cache for non-bundled assets
let url = new URL(path, window.location.origin);
Expand All @@ -99,13 +100,16 @@ class AssetManager {
url.searchParams.append("v", version_string);
}
const response = await fetch(url.toString());
const body = await response.text();
me.eval_assets(path, body);
fetched_assets[path] = await response.text();
}

frappe.dom.freeze();
const fetch_promises = items.map(fetch_item);
Promise.all(fetch_promises).then(() => {
items.forEach((path) => {
let body = fetched_assets[path];
me.eval_assets(path, body);
});
frappe.dom.unfreeze();
callback?.();
});
Expand Down

0 comments on commit a7b7af8

Please sign in to comment.