-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intl.Segmenter isn't available in Firefox #818
Comments
Actually we polyfill Intl and Temporal already in the client (the browser's main thread), so it's already available to Space Script: https://github.com/silverbulletmd/silverbullet/blob/main/common/space_script.ts#L12 , what I missed is that this polyfill isn't available in web workers, which plugs run in 🤦🏻 Two possible fixes: also expose this polyfill in plugs code, the other is indeed to fall back to a simpler implementation. I'd have to check how big the polyfill is (because this size would be added to each individual plug JS bundle), but perhaps the fallback you suggest is the more pragmatic solution. |
Thinking about this more: let's go with the fallback approach, if you could give that a try I'd much appreciate it! |
I'm willing to try. It might take a couple of days though. My computer decided to spontaneously die so I have to wait for a new one. |
I just tried to create a function for displaying a relative time and noticed the issue that I cannot use It looks like the Intl exported from js-temporal/polyfill exports an I guess this also causes some of the properties from
This is the script I tried to write to get relative times.silverbullet.registerFunction("relativeTime", (time, baseTime = new Date()) => {
const relForm = new Intl.RelativeTimeFormat('en');
const relative = (+new Date(time) - +new Date(baseTime)) / 1000;
const absDiff = Math.abs(relative);
const units = [
[1, "second"],
[60, "minute"],
[60 * 60, "hour"],
[60 * 60 * 24, "day"],
[60 * 60 * 24 * 7, "week"],
[60 * 60 * 24 * 30, "month"],
[60 * 60 * 24 * 365, "year"],
];
if (absDiff < 1) {
return relative < 0 ? "just now" : "now";
}
for (let i = 0; i < units.length; i++) {
const [factor, unit] = units[i];
if (i === units.length - 1 || absDiff / units[i + 1][0] < 1) {
return relForm.format(relative / factor, unit);
}
}
}); |
@daniel-michel I think you fixed this since with #836 correct? |
Yes |
It seems that the changes in 89e2e7a broke Silverbullet running in Firefox, due to the usage of
Intl.Segmenter
. This is only available in Firefox Nightly.Is there any thoughts around browser compatibility?
Would it be a good idea to add a check for
Intl.Segmenter
availability and fall back to just splitting by whitespace and taking the n words before/after the index? I might be able to make a PR for that if that seems like a good idea.The text was updated successfully, but these errors were encountered: