temporal_js_polyfill
Loads the TC39 Temporal polyfill for Dart web apps that need to support browsers without native Temporal. Pairs with temporal or temporal_js.
Features
loadTemporalPolyfill()— injectstemporal-polyfillinto the page as a<script>tag and resolves once the globalTemporalobject is available- Cross-platform safe — on native / VM platforms every symbol is a no-op or a trivially-true constant, so the same
main.dartcompiles on every target without conditional imports - Self-hostable — pass a custom
srcURL to pin a specific polyfill version or serve it from your own CDN
Getting started
dependencies:
temporal: ^0.0.1
temporal_js_polyfill: ^0.0.1
Usage
Call loadTemporalPolyfill() once at app startup, before any Temporal types are used:
import 'package:temporal/temporal.dart';
import 'package:temporal_js_polyfill/temporal_js_polyfill.dart';
void main() async {
await loadTemporalPolyfill(); // no-op on native and modern browsers
runApp(MyApp());
}
To use a self-hosted or pinned polyfill bundle:
await loadTemporalPolyfill(
src: 'https://cdn.example.com/temporal-polyfill@1.0.0/index.umd.js',
);
Browser support
The polyfill targets browsers that implement modern JS but lack the native Temporal API (e.g. Firefox, Safari prior to their respective Temporal shipping dates). On browsers with native Temporal, loadTemporalPolyfill() returns immediately without injecting any script.
Additional information
Libraries
- temporal_js_polyfill
- Loads the TC39 Temporal polyfill for browsers that don't yet support it natively.