Static Resources with async Functions Behave Inconsistently

When you use lightning/platformResourceLoader in Lightning web components (LWC) to access static resources and Lightning Web Security (LWS) is enabled, it’s possible that some APIs in those static resources exhibit inconsistent behavior among various browsers.

When LWS is enabled, JavaScript async functions that are used from a static resource work in Chromium-based browsers, but don’t work in Firefox currently. The issue is a bug in Firefox.

You can get around this issue in Firefox by pre-compiling the code that’s in the static resource so the async function is replaced by equivalent code.

This Babel plugin is recommended if you’re having issues with async functions in static resources: https://babeljs.io/docs/en/babel-plugin-transform-async-to-generator

Alternatively, you can refactor to use another approach, such as JavaScript promises.

See Also

Release Preview

This release is in preview. Features described here don't become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can't guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.