gemi 0.54.0 → 0.54.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{b as x,d as D}from"./chunk-26r8dcxd.js";import{l as y,m as I}from"./chunk-f4e7fh95.js";import"./chunk-gn9zjgep.js";import"./chunk-f418jh9k.js";import"./chunk-agabw2w1.js";import"./chunk-fcqc3e3r.js";import"./chunk-7f5ad759.js";import{IncomingMessage as T,ServerResponse as g}from"http";import{Socket as w}from"net";import{join as E}from"path";import{createServer as k}from"vite";function N(H){return H.replace(/\x1b\[[0-9;]*m/g,"").replace(/\[[0-9;]*m/g,"").replace(/\n\s*\n/g,`
2
+ import{b as x,d as D}from"./chunk-h6xsczr8.js";import{l as y,m as I}from"./chunk-f4e7fh95.js";import"./chunk-gn9zjgep.js";import"./chunk-f418jh9k.js";import"./chunk-agabw2w1.js";import"./chunk-fcqc3e3r.js";import"./chunk-7f5ad759.js";import{IncomingMessage as T,ServerResponse as g}from"http";import{Socket as w}from"net";import{join as E}from"path";import{createServer as k}from"vite";function N(H){return H.replace(/\x1b\[[0-9;]*m/g,"").replace(/\[[0-9;]*m/g,"").replace(/\n\s*\n/g,`
3
3
  `).split(`
4
4
  `).map((J)=>J.trim()).filter((J)=>J.length>0).join(`
5
5
  `).trim()}function R(H){return`
@@ -1699,26 +1699,58 @@ function createHandle(id, locales, load) {
1699
1699
  }
1700
1700
  //#endregion
1701
1701
  //#region client/useLocale.ts
1702
- var setCookie = async (locale) => {
1702
+ var LOCALE_COOKIE = "i18n-locale";
1703
+ var LOCALE_COOKIE_MAX_AGE = 3600 * 24 * 365;
1704
+ /**
1705
+ * The active locale lives in two places: the URL segment `setLocale` navigates
1706
+ * to, and the `i18n-locale` cookie the server falls back to when the URL has no
1707
+ * segment — which is exactly the case for the default locale. Both have to be in
1708
+ * place *before* the navigation asks for route data, or `Translator.detectLocale`
1709
+ * answers the request with a redirect back to the locale the cookie still names.
1710
+ *
1711
+ * Hence a synchronous `document.cookie` write rather than an awaited one. The
1712
+ * previous implementation awaited `cookieStore.set()` and hung the navigation off
1713
+ * its `.then()`; that promise is reported to never settle on iOS Safari, so the
1714
+ * `.then()` never ran and changing the language became a silent no-op — no
1715
+ * rejection, nothing for an error reporter to pick up. A synchronous write cannot
1716
+ * hang and cannot fail asynchronously, so nothing is left to gate navigation on.
1717
+ */
1718
+ function persistLocale(locale) {
1719
+ if (typeof document === "undefined") return;
1703
1720
  try {
1704
- return await globalThis.cookieStore.set("i18n-locale", locale);
1705
- } catch (err) {
1706
- return await fetch(`/api/__gemi__/services/i18n/set-locale/${locale}`);
1707
- }
1708
- };
1721
+ document.cookie = [
1722
+ `${LOCALE_COOKIE}=${encodeURIComponent(locale)}`,
1723
+ `Max-Age=${LOCALE_COOKIE_MAX_AGE}`,
1724
+ "SameSite=Strict",
1725
+ "Path=/"
1726
+ ].join("; ");
1727
+ } catch {}
1728
+ }
1729
+ /**
1730
+ * `onLocaleChange` is a server-side hook, so it takes a request to fire it. The
1731
+ * switch must not wait on that round trip, nor be cancelled by one that fails —
1732
+ * including one that fails *synchronously*: `fetch` is absent in some old
1733
+ * WebViews, and an unguarded call would throw before the navigation ran, which
1734
+ * is the same silent no-op this hook exists to prevent through another door.
1735
+ */
1736
+ function notifyLocaleChange(locale) {
1737
+ try {
1738
+ fetch(`/api/__gemi__/services/i18n/set-locale/${encodeURIComponent(locale)}`).catch(() => {});
1739
+ } catch {}
1740
+ }
1709
1741
  function useLocale() {
1710
1742
  const { i18n } = useRouteData();
1711
1743
  const { pathname, search } = useLocation();
1712
1744
  const { replace } = useNavigate();
1713
1745
  const params = useParams();
1714
1746
  const setLocale = async (locale) => {
1747
+ persistLocale(locale);
1748
+ notifyLocaleChange(locale);
1715
1749
  const urlSearchParams = new URLSearchParams(search);
1716
- setCookie(locale).then(() => {
1717
- replace(pathname, {
1718
- locale,
1719
- search: Object.fromEntries(urlSearchParams.entries()),
1720
- params
1721
- });
1750
+ await replace(pathname, {
1751
+ locale,
1752
+ search: Object.fromEntries(urlSearchParams.entries()),
1753
+ params
1722
1754
  });
1723
1755
  };
1724
1756
  return [i18n.currentLocale, setLocale];