Proposal: Handling Polyfills in Application and Package Dependencies #1315
Replies: 3 comments 7 replies
-
This all sounds good to me! I have one question though: what is the scenario where we need to be importing the polyfill for testing? If the argument is that those are application concerns then perhaps it's also an argument that those sorts of tests belong in pie-aperture, and therefore don't need to be listed in the component's devDependencies at all? What do you think? If it's for something like visual regression tests so that we can catch regressions early before they reach aperture then that's probably okay as-is. |
Beta Was this translation helpful? Give feedback.
-
Thanks @kevinrodrigues, this sounds like a good proposal. One minor nitpick, please could we specify that we are supporting iOS Safari 14+? I believe it's the same version for MacOS, but I do personally think we should make Polyfill recommendations for consumers. Otherwise, I can see us constantly being asked for suggestions. My question would be: Going forward, how do we ensure we are identifying features that require polyfills? Can we add a step to our development and review process to prevent things getting merged without being spotted? |
Beta Was this translation helpful? Give feedback.
-
This all looks good, and I agree with the points raised above, which it looks like have been addressed now potentially. The only thing that I think could be useful in the future, would be to provide a PIE polyfill plugin that loads in the polyfills needed to match our current level of browser support. I think we'd need to scope this out properly, but in essence all it would be is an NPM package that loads in a bunch of polyfills for users who want to match our own level of browser support (maybe they can also opt in to which polyfills through a small amount of config). For example, currently this package would include the dialog polyfill, form polyfills etc. I see this as being useful for a couple of reasons:
Would be good to hear thoughts on this. This absolutely wouldn't be a part of the current bundling epic, but most likely it's own mini-epic that we could look at doing in Q2 onwards. |
Beta Was this translation helpful? Give feedback.
-
Proposal: Handling Polyfills in Application and Package Dependencies
I refer to
DSW-1780
in this proposal.Key
Application Developer: - An application developer = consuming team / application
Polyfills: - Polyfills are code snippets or scripts that provide modern functionality in older browsers that lack native support for those features. They help ensure consistent behavior across different browsers.
Package Maintainer: - A package maintainer is an individual or group responsible for managing and maintaining a software package. In the context of this discussion, I refer to those who develop and release packages (e.g., libraries, components) that can be used by application developers. = i.e Design System Team (PIE)
Preface
This proposal suggests a best practice for handling polyfills in both application and package dependencies. The aim is to streamline the integration of polyfills, recognising them as an application concern, and allowing flexibility in choosing the necessary polyfills based on browser support. Additionally, it addresses the need for aligning components with Lit's recommendations for enhanced compatibility.
Proposal
For Application Developers
Direct Dependency on Polyfills: Polyfills are an application concern, and the application should directly depend on them rather than individual packages. This allows the application developer to have control over the polyfills used based on the browsers they need to support.
Documentation Clarity: Component documentation should clearly identify any APIs that require polyfills. This allows the application developer to make informed decisions on which polyfills to include based on the specific needs of their application. In my opinion we should probably not document it and just leave it to the application developer to polyfill as required on a as needs basis.
For Package Maintainers
Polyfills in devDependencies: Packages may need to depend on polyfills for tests and demos (See section
DevDependencies and Polyfills for Tests
for more detail). If polyfills are required, they should only be included in thedevDependencies
section of the package'spackage.json
file. This ensures that polyfills are not included in the production build, preventing unnecessary dependencies for end-users.Lit's Recommendations Compliance: Components should align with Lit's recommendations to enhance compatibility and interoperability. Current components not following Lit's guidelines should be updated to ensure a consistent and well-supported development experience.
Example
Application Dependencies
Component Documentation
Package Dependencies
What does this mean for our current components?
Existing Polyfills within Components
Several of our current components, such as
pie-modal
, include internal polyfills. As part of the proposed changes, we aim to refactor these components to remove internal polyfills. This move will ensure a cleaner separation of concerns and empower application developers to manage polyfills based on their specific needs.Example: Refactoring
pie-modal
Current State:
pie-modal
includes an internal polyfill for certain browsers.Proposed Changes:
Polyfill Removal:
pie-modal
component.Documentation Update:
pie-modal
readme documentation to clearly communicate the removal of the internal polyfill and document that the application developer will require a polyfill if they require support in older browsers e.g IOS Safari 14 etc.Benefits of Refactoring
Cleaner Components:
Application Developers:
DevDependencies and Polyfills for Tests
In addition to the changes mentioned above, it might be essential to address the use of polyfills specifically for testing, demos, or mocking. These polyfills should be included in the
devDependencies
section of the package'spackage.json
file. This practice ensures that these polyfills are only installed when developers are working on the package, avoiding unnecessary dependencies in production builds.Updated
package.json
for Tests:Discussion
Feel free to leave any comments.
Beta Was this translation helpful? Give feedback.
All reactions