@arcote.tech/platform 0.7.8 → 0.7.10

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arcote.tech/platform",
3
3
  "type": "module",
4
- "version": "0.7.8",
4
+ "version": "0.7.10",
5
5
  "private": false,
6
6
  "author": "Przemysław Krasiński [arcote.tech]",
7
7
  "description": "Arc Platform — module system, router, layout, theme, i18n, platform app shell",
@@ -14,12 +14,12 @@
14
14
  "type-check": "tsc --noEmit"
15
15
  },
16
16
  "dependencies": {
17
- "@arcote.tech/arc-ds": "^0.7.8",
18
- "@arcote.tech/arc-react": "^0.7.8"
17
+ "@arcote.tech/arc-ds": "^0.7.10",
18
+ "@arcote.tech/arc-react": "^0.7.10"
19
19
  },
20
20
  "peerDependencies": {
21
- "@arcote.tech/arc": "^0.7.8",
22
- "@arcote.tech/arc-otel": "^0.7.8",
21
+ "@arcote.tech/arc": "^0.7.10",
22
+ "@arcote.tech/arc-otel": "^0.7.10",
23
23
  "@lingui/core": "^5.0.0",
24
24
  "@lingui/react": "^5.0.0",
25
25
  "framer-motion": "^12.0.0",
package/src/i18n.tsx CHANGED
@@ -37,6 +37,14 @@ export function I18nProvider({
37
37
  return defaultLocale;
38
38
  });
39
39
  const [messages, setMessages] = useState<Record<string, string>>({});
40
+ // Bez `ready` pierwszy paint renderuje aplikację z pustym `messages`
41
+ // (bo `loadMessages` jest async w useEffect). `<Trans>foo</Trans>` w tej
42
+ // klatce pokazuje surowe "foo" zamiast tłumaczenia, a po dociągnięciu
43
+ // katalogu odbywa się re-render z poprawnym tekstem — widoczny flash.
44
+ // Wstrzymanie renderu do pierwszego setMessages eliminuje flash.
45
+ // Gdy `locales` jest puste (brak translations skonfigurowanych),
46
+ // setMessages też się wywoła (z `{}`) i `ready` przejdzie na true od razu.
47
+ const [ready, setReady] = useState(false);
40
48
 
41
49
  const setLocale = useCallback(
42
50
  async (newLocale: string) => {
@@ -49,9 +57,11 @@ export function I18nProvider({
49
57
  );
50
58
 
51
59
  useEffect(() => {
52
- setLocale(locale);
60
+ setLocale(locale).finally(() => setReady(true));
53
61
  }, []);
54
62
 
63
+ if (!ready) return null;
64
+
55
65
  return (
56
66
  <I18nContext.Provider value={{ locale, messages, setLocale, locales }}>
57
67
  {children}
@@ -68,6 +68,17 @@ interface I18nConfig {
68
68
  sourceLocale: string;
69
69
  }
70
70
 
71
+ // Empty = `/api/translations` zwróciło puste (brak translations
72
+ // skonfigurowanych w `package.json#arc.translations`). I18nProvider działa
73
+ // wtedy w trybie pass-through — `<Trans>` renderuje surowy tekst, switcher
74
+ // języka się nie pokazuje, ale `useI18n()` nadal zwraca poprawny obiekt.
75
+ const EMPTY_I18N_CONFIG: I18nConfig = { locales: {}, sourceLocale: "en" };
76
+
77
+ // `null` = jeszcze nie wiadomo czy translations są skonfigurowane (fetch
78
+ // trwa). PlatformAppInner czeka na `null → config` żeby zmountować
79
+ // I18nProvider RAZ z właściwymi propsami; locale state w providerze jest
80
+ // w useState bez sync z propsami, więc remount po zmianie propsów
81
+ // wprowadziłby dodatkowy flash.
71
82
  function useI18nConfig(apiUrl: string): I18nConfig | null {
72
83
  const [config, setConfig] = useState<I18nConfig | null>(null);
73
84
 
@@ -80,9 +91,11 @@ function useI18nConfig(apiUrl: string): I18nConfig | null {
80
91
  const localesMap: Record<string, string> = {};
81
92
  for (const l of data.locales) localesMap[l] = l;
82
93
  setConfig({ locales: localesMap, sourceLocale: data.sourceLocale });
94
+ } else {
95
+ setConfig(EMPTY_I18N_CONFIG);
83
96
  }
84
97
  })
85
- .catch(() => {});
98
+ .catch(() => setConfig(EMPTY_I18N_CONFIG));
86
99
  }, [apiUrl]);
87
100
 
88
101
  return config;
@@ -139,31 +152,30 @@ function PlatformAppInner({
139
152
  [apiUrl],
140
153
  );
141
154
 
142
- let inner = (
143
- <ThemeProvider>
144
- <DesignSystemProvider
145
- variants={{ ...getVariantOverrides(), ...variants }}
146
- >
147
- <TooltipProvider>
148
- <ArcLayoutProvider>{content}</ArcLayoutProvider>
149
- </TooltipProvider>
150
- </DesignSystemProvider>
151
- </ThemeProvider>
155
+ // Czekamy na pierwszą odpowiedź `/api/translations` — wtedy montujemy
156
+ // I18nProvider RAZ z właściwymi propsami (real locales albo
157
+ // pass-through). Gwarantuje to że `useI18n()` zawsze ma kontekst, a
158
+ // texty `<Trans>` nigdy nie flashują surową wartością przed tłumaczeniem.
159
+ if (!i18nConfig) return null;
160
+
161
+ const inner = (
162
+ <I18nProvider
163
+ defaultLocale={i18nConfig.sourceLocale}
164
+ locales={i18nConfig.locales}
165
+ loadMessages={loadMessages}
166
+ >
167
+ <ThemeProvider>
168
+ <DesignSystemProvider
169
+ variants={{ ...getVariantOverrides(), ...variants }}
170
+ >
171
+ <TooltipProvider>
172
+ <ArcLayoutProvider>{content}</ArcLayoutProvider>
173
+ </TooltipProvider>
174
+ </DesignSystemProvider>
175
+ </ThemeProvider>
176
+ </I18nProvider>
152
177
  );
153
178
 
154
- // Wrap with I18nProvider if translations are configured
155
- if (i18nConfig) {
156
- inner = (
157
- <I18nProvider
158
- defaultLocale={i18nConfig.sourceLocale}
159
- locales={i18nConfig.locales}
160
- loadMessages={loadMessages}
161
- >
162
- {inner}
163
- </I18nProvider>
164
- );
165
- }
166
-
167
179
  return (
168
180
  <ModelProvider>
169
181
  <PlatformModelProvider