Skip to content

Proposal for external polyfills being included in shim #183

@matt-gadd

Description

@matt-gadd

Enhancement
At the moment, any third party polyfills or ponyfills used by or recommended to be used with dojo have to be included separately, this causes a few pain points:

  • inconsistency with how users are used to using other ponyfills from shim
  • relies on them knowing the correct packages to install from npm (or us documenting it effectively)
  • relies on the end user knowing how to include/use the polyfill or ponyfill
  • relies on the package being installed to have correct/compatible types, or an equivalent @types package
  • does not allow us to elide the polyfills/ponyfills based on whether they are implemented in the specific browser

To solve this the proposal is to include a number of external polyfills/ponyfills in dojo/framework and re-export them to the end user as if they were any other kind of dojo shim. For example for IntersectionObserver may look like:

module: @dojo/framework/shim/IntersectionObserver
import global from '@dojo/framework/shim/global';
import 'intersection-observer';

export default global.IntersectionObserver as IntersectionObserver;

The end user would then leverage @dojo/framework/shim/IntersectionObserver and use it as a ponyfill (regardless of whether it is a ponyfill or not).

From this, we can then also expand our current build capabilities to correctly include the polyfills based on whether a) they are used/imported, and b) if they are actually needed by the users browser based on a runtime check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestnextIssue/Pull Request for the next major version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions