Skip to content

Temporal support in browsers with polyfill fallback #156

@Gerschtli

Description

@Gerschtli

Hey, I am currently using devalue as part of a sveltekit project and I really like the new Temporal API. Unfortunately, I can not send Temporal objects to the client with e.g. a Safari browser because I get

ReferenceError: Can't find variable: Temporal

I tried it with the following in the hooks.ts file:

import { Temporal } from '@js-temporal/polyfill';
import type { Transport } from '@sveltejs/kit';

export const transport: Transport = {
	'Temporal.Duration': {
		encode: (value) => value instanceof Temporal.Duration && [value.toString()],
		decode: ([value]) => Temporal.Duration.from(value),
	},
	'Temporal.Instant': {
		encode: (value) => value instanceof Temporal.Instant && [value.toString()],
		decode: ([value]) => Temporal.Instant.from(value),
	}
}

It would be really great to somehow opt in to loading a polyfill as a fallback (e.g. "@js-temporal/polyfill") to at least ensure that the app still works. Or is there currently any workaround possible so that I can achieve this goal? Right now, I am loading this polyfill already in several places but it seems like I can not override how the Temporal object should parsed/stringified.

Thank you very much in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions