@lovalingo/lovalingo 0.5.8 → 0.5.9

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,4 +1,4 @@
1
- import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
1
+ import React, { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
2
2
  import { LovalingoContext } from '../context/LovalingoContext';
3
3
  import { LangRoutingContext } from '../context/LangRoutingContext';
4
4
  import { LovalingoAPI } from '../utils/api';
@@ -15,6 +15,8 @@ import { LanguageSwitcher } from './LanguageSwitcher';
15
15
  const LOCALE_STORAGE_KEY = 'Lovalingo_locale';
16
16
  const LOADING_BG_STORAGE_PREFIX = "Lovalingo_loading_bg_color";
17
17
  const BRANDING_STORAGE_PREFIX = "Lovalingo_branding_enabled";
18
+ // Why: run initial load before first paint on the client to avoid a prehide flash; useEffect on SSR.
19
+ const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
18
20
  export const LovalingoProvider = ({ children, apiKey: apiKeyProp, publicAnonKey, defaultLocale, locales, apiBase = 'https://cdn.lovalingo.com', routing = 'path', // Default to path mode (SEO-friendly, recommended)
19
21
  autoPrefixLinks = true, overlayBgColor, autoApplyRules = true, switcherPosition = 'bottom-right', switcherOffsetY = 20, switcherTheme = 'dark', editMode: initialEditMode = false, editKey = 'KeyE', pathNormalization = { enabled: true }, // Enable by default
20
22
  mode = 'dom', // Default to legacy DOM mode for backward compatibility
@@ -524,7 +526,7 @@ navigateRef, // For path mode routing
524
526
  detectLocaleRef.current = detectLocale;
525
527
  }, [detectLocale]);
526
528
  // Initialize
527
- useEffect(() => {
529
+ useIsomorphicLayoutEffect(() => {
528
530
  const initialLocale = detectLocaleRef.current();
529
531
  lastNormalizedPathRef.current = processPath(window.location.pathname, enhancedPathConfig);
530
532
  // Track initial page (fallback discovery for pages not present in the routes feed).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovalingo/lovalingo",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "description": "React translation runtime with i18n routing, deterministic bundles + DOM rules, and zero-flash rendering.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",