Skip to content

loadScript, loadCSS doesn't wait for script loading / parsing when invoked multiple times in parallel #399

@yugandhar02

Description

@yugandhar02

Expected Behaviour

When loadScript or loadCSS is called multiple times in parallel, the subsequent invocations after first call doesn't wait for script loading or parsing. It returns resolved promise

Actual Behaviour

loadScript or loadCSS should return pending promise if loading or parsing is still in progress

Steps to Reproduce

  1. call loadScript or loadCSS multiple times in same page with same src url

Sample Code that illustrates the problem

async function renderVideo(block) {
  await Promise.all([
    loadCSS(VIDEO_JS_CSS),
    loadScript(VIDEO_JS_SCRIPT),
  ]);
  
  // render
}

async function decorateCard(card) {
  await renderVideo(card);
}

await Promise.all([
  decorateCard(card1),
  decorateCard(card2),
  decorateCard(card3),
]

Test page where it fails:
https://issue-399-demo--franklin-assets-selector--hlxsites.hlx.page/_drafts/yug/demo

Test page with fix applied:
https://issue-399-fix--franklin-assets-selector--hlxsites.hlx.page/_drafts/yug/demo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions