@prenta/admin 2.16.4 → 2.16.5

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @actuate-media/cms-admin
2
2
 
3
+ ## 2.16.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 5b188d4: The admin locale picker no longer crashes when browser storage is unavailable, such as in a private window; it falls back to the default locale.
8
+
3
9
  ## 2.16.4
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=locale-provider-storage.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale-provider-storage.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/components/locale-provider-storage.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,59 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ // @vitest-environment happy-dom
3
+ import { act, fireEvent, render, screen } from '@testing-library/react';
4
+ import { afterEach, describe, expect, it, vi } from 'vitest';
5
+ import { LocaleProvider, useLocale } from '../../components/LocaleProvider.js';
6
+ const config = {
7
+ i18n: {
8
+ defaultLocale: 'en',
9
+ locales: [
10
+ { code: 'en', label: 'English' },
11
+ { code: 'es', label: 'Spanish' },
12
+ ],
13
+ },
14
+ };
15
+ function Probe() {
16
+ const { activeLocale, setLocale } = useLocale();
17
+ return (_jsxs("button", { type: "button", onClick: () => setLocale('es'), children: ["locale:", activeLocale] }));
18
+ }
19
+ function renderProvider() {
20
+ return render(_jsx(LocaleProvider, { config: config, children: _jsx(Probe, {}) }));
21
+ }
22
+ describe('LocaleProvider storage guard (#1210)', () => {
23
+ afterEach(() => {
24
+ vi.unstubAllGlobals();
25
+ });
26
+ it('renders with the default locale when localStorage is undefined', async () => {
27
+ vi.stubGlobal('localStorage', undefined);
28
+ renderProvider();
29
+ await act(async () => { });
30
+ const button = screen.getByRole('button');
31
+ expect(button.textContent).toBe('locale:en');
32
+ fireEvent.click(button);
33
+ expect(button.textContent).toBe('locale:es');
34
+ });
35
+ it('renders with the default locale when getItem and setItem throw', async () => {
36
+ const throwing = {
37
+ getItem: vi.fn(() => {
38
+ throw new DOMException('denied', 'SecurityError');
39
+ }),
40
+ setItem: vi.fn(() => {
41
+ throw new DOMException('denied', 'QuotaExceededError');
42
+ }),
43
+ removeItem: vi.fn(),
44
+ clear: vi.fn(),
45
+ key: vi.fn(() => null),
46
+ length: 0,
47
+ };
48
+ vi.stubGlobal('localStorage', throwing);
49
+ renderProvider();
50
+ await act(async () => { });
51
+ const button = screen.getByRole('button');
52
+ expect(throwing.getItem).toHaveBeenCalled();
53
+ expect(button.textContent).toBe('locale:en');
54
+ fireEvent.click(button);
55
+ expect(throwing.setItem).toHaveBeenCalledWith('prenta-locale', 'es');
56
+ expect(button.textContent).toBe('locale:es');
57
+ });
58
+ });
59
+ //# sourceMappingURL=locale-provider-storage.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale-provider-storage.test.js","sourceRoot":"","sources":["../../../src/__tests__/components/locale-provider-storage.test.tsx"],"names":[],"mappings":";AAAA,gCAAgC;AAChC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AACvE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE5D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAA;AAE9E,MAAM,MAAM,GAAG;IACb,IAAI,EAAE;QACJ,aAAa,EAAE,IAAI;QACnB,OAAO,EAAE;YACP,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE;YAChC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE;SACjC;KACF;CACF,CAAA;AAED,SAAS,KAAK;IACZ,MAAM,E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,GAAG,KAAK,CAAA;aAAE,CAAC,CAAA;YACpE,cAAc,CAAC,EAAE,MAAM,CAAA;SACxB,CAAA;KACF,CAAA;IACD,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,mBAAmB,2CAuBvE"}
@@ -10,19 +10,41 @@ export function useLocale() {
10
10
  return useContext(LocaleContext);
11
11
  }
12
12
  const STORAGE_KEY = 'prenta-locale';
13
+ // Storage can be missing (Node without --localstorage-file, SSR) or throw
14
+ // (private windows, blocked site data); the locale then stays in memory only.
15
+ function readStoredLocale() {
16
+ try {
17
+ if (typeof localStorage === 'undefined' || !localStorage)
18
+ return null;
19
+ return localStorage.getItem(STORAGE_KEY);
20
+ }
21
+ catch {
22
+ return null;
23
+ }
24
+ }
25
+ function writeStoredLocale(locale) {
26
+ try {
27
+ if (typeof localStorage === 'undefined' || !localStorage)
28
+ return;
29
+ localStorage.setItem(STORAGE_KEY, locale);
30
+ }
31
+ catch {
32
+ // Storage unavailable: keep the choice for this session only.
33
+ }
34
+ }
13
35
  export function LocaleProvider({ config, children }) {
14
36
  const locales = config.i18n?.locales ?? [];
15
37
  const defaultLocale = config.i18n?.defaultLocale ?? 'en';
16
38
  const [activeLocale, setActiveLocale] = useState(defaultLocale);
17
39
  useEffect(() => {
18
- const stored = localStorage.getItem(STORAGE_KEY);
40
+ const stored = readStoredLocale();
19
41
  if (stored && locales.some((l) => l.code === stored)) {
20
42
  setActiveLocale(stored);
21
43
  }
22
44
  }, [locales]);
23
45
  const setLocale = useCallback((locale) => {
24
46
  setActiveLocale(locale);
25
- localStorage.setItem(STORAGE_KEY, locale);
47
+ writeStoredLocale(locale);
26
48
  }, []);
27
49
  return (_jsx(LocaleContext.Provider, { value: { activeLocale, setLocale, locales }, children: children }));
28
50
  }
@@ -1 +1 @@
1
- {"version":3,"file":"LocaleProvider.js","sourceRoot":"","sources":["../../src/components/LocaleProvider.tsx"],"names":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AAa,GAAG,MAAM,CAAC,IAAI,EAAE,aAAa,IAAI,IAAI,CAAA;IAExD,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,CAAA;IAE/D,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,MAAM,GAAG,gBAAgB,EAAE,CAAA;QACjC,IAAI,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,EAAE,CAAC;YACrD,eAAe,CAAC,MAAM,CAAC,CAAA;QACzB,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAEb,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,MAAc,EAAE,EAAE;QAC/C,eAAe,CAAC,MAAM,CAAC,CAAA;QACvB,iBAAiB,CAAC,MAAM,CAAC,CAAA;IAC3B,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,CACL,KAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,YAChE,QAAQ,GACc,CAC1B,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prenta/admin",
3
- "version": "2.16.4",
3
+ "version": "2.16.5",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -99,16 +99,16 @@
99
99
  "tailwindcss": "^4.0.0",
100
100
  "typescript": "^5.7.0",
101
101
  "vitest": "^4.1.12",
102
- "@prenta/component-blocks": "0.3.2",
103
102
  "@prenta/core": "8.21.11",
104
103
  "@prenta/plugin-ai": "4.0.2",
104
+ "@prenta/component-blocks": "0.3.2",
105
105
  "@prenta/plugin-blocks": "1.0.2",
106
106
  "@prenta/plugin-commerce": "1.0.2",
107
- "@prenta/plugin-forms": "1.0.3",
108
107
  "@prenta/plugin-media": "1.0.2",
109
108
  "@prenta/plugin-navigation": "1.1.1",
110
109
  "@prenta/plugin-seo": "2.0.2",
111
- "@prenta/sections-react": "0.20.27"
110
+ "@prenta/sections-react": "0.20.27",
111
+ "@prenta/plugin-forms": "1.0.3"
112
112
  },
113
113
  "scripts": {
114
114
  "build": "tsc --project tsconfig.json && npx @tailwindcss/cli -i src/styles/build-input.css -o dist/prenta-admin.css --minify && node scripts/copy-font-files.mjs",
@@ -0,0 +1,78 @@
1
+ // @vitest-environment happy-dom
2
+ import { act, fireEvent, render, screen } from '@testing-library/react'
3
+ import { afterEach, describe, expect, it, vi } from 'vitest'
4
+
5
+ import { LocaleProvider, useLocale } from '../../components/LocaleProvider.js'
6
+
7
+ const config = {
8
+ i18n: {
9
+ defaultLocale: 'en',
10
+ locales: [
11
+ { code: 'en', label: 'English' },
12
+ { code: 'es', label: 'Spanish' },
13
+ ],
14
+ },
15
+ }
16
+
17
+ function Probe() {
18
+ const { activeLocale, setLocale } = useLocale()
19
+ return (
20
+ <button type="button" onClick={() => setLocale('es')}>
21
+ locale:{activeLocale}
22
+ </button>
23
+ )
24
+ }
25
+
26
+ function renderProvider() {
27
+ return render(
28
+ <LocaleProvider config={config}>
29
+ <Probe />
30
+ </LocaleProvider>,
31
+ )
32
+ }
33
+
34
+ describe('LocaleProvider storage guard (#1210)', () => {
35
+ afterEach(() => {
36
+ vi.unstubAllGlobals()
37
+ })
38
+
39
+ it('renders with the default locale when localStorage is undefined', async () => {
40
+ vi.stubGlobal('localStorage', undefined)
41
+
42
+ renderProvider()
43
+ await act(async () => {})
44
+
45
+ const button = screen.getByRole('button')
46
+ expect(button.textContent).toBe('locale:en')
47
+
48
+ fireEvent.click(button)
49
+ expect(button.textContent).toBe('locale:es')
50
+ })
51
+
52
+ it('renders with the default locale when getItem and setItem throw', async () => {
53
+ const throwing = {
54
+ getItem: vi.fn(() => {
55
+ throw new DOMException('denied', 'SecurityError')
56
+ }),
57
+ setItem: vi.fn(() => {
58
+ throw new DOMException('denied', 'QuotaExceededError')
59
+ }),
60
+ removeItem: vi.fn(),
61
+ clear: vi.fn(),
62
+ key: vi.fn(() => null),
63
+ length: 0,
64
+ }
65
+ vi.stubGlobal('localStorage', throwing)
66
+
67
+ renderProvider()
68
+ await act(async () => {})
69
+
70
+ const button = screen.getByRole('button')
71
+ expect(throwing.getItem).toHaveBeenCalled()
72
+ expect(button.textContent).toBe('locale:en')
73
+
74
+ fireEvent.click(button)
75
+ expect(throwing.setItem).toHaveBeenCalledWith('prenta-locale', 'es')
76
+ expect(button.textContent).toBe('locale:es')
77
+ })
78
+ })
@@ -20,6 +20,26 @@ export function useLocale() {
20
20
 
21
21
  const STORAGE_KEY = 'prenta-locale'
22
22
 
23
+ // Storage can be missing (Node without --localstorage-file, SSR) or throw
24
+ // (private windows, blocked site data); the locale then stays in memory only.
25
+ function readStoredLocale(): string | null {
26
+ try {
27
+ if (typeof localStorage === 'undefined' || !localStorage) return null
28
+ return localStorage.getItem(STORAGE_KEY)
29
+ } catch {
30
+ return null
31
+ }
32
+ }
33
+
34
+ function writeStoredLocale(locale: string): void {
35
+ try {
36
+ if (typeof localStorage === 'undefined' || !localStorage) return
37
+ localStorage.setItem(STORAGE_KEY, locale)
38
+ } catch {
39
+ // Storage unavailable: keep the choice for this session only.
40
+ }
41
+ }
42
+
23
43
  export interface LocaleProviderProps {
24
44
  config: {
25
45
  i18n?: {
@@ -38,7 +58,7 @@ export function LocaleProvider({ config, children }: LocaleProviderProps) {
38
58
  const [activeLocale, setActiveLocale] = useState(defaultLocale)
39
59
 
40
60
  useEffect(() => {
41
- const stored = localStorage.getItem(STORAGE_KEY)
61
+ const stored = readStoredLocale()
42
62
  if (stored && locales.some((l) => l.code === stored)) {
43
63
  setActiveLocale(stored)
44
64
  }
@@ -46,7 +66,7 @@ export function LocaleProvider({ config, children }: LocaleProviderProps) {
46
66
 
47
67
  const setLocale = useCallback((locale: string) => {
48
68
  setActiveLocale(locale)
49
- localStorage.setItem(STORAGE_KEY, locale)
69
+ writeStoredLocale(locale)
50
70
  }, [])
51
71
 
52
72
  return (