judgeme-hydrogen-fixed 1.0.1 → 1.0.3

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
@@ -5,14 +5,26 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.2] - 2026-01-06
9
+
10
+ ### Fixed
11
+
12
+ - Fixed duplicate widgets appearing on initial page load
13
+ - Route change effect now skips first render to avoid double initialization
14
+ - Initial refresh is now only triggered by the script loading effect
15
+ - Fixed widgets not displaying on initial page load
16
+ - Added retry mechanism to wait for widget elements in DOM before initializing
17
+
8
18
  ## [1.0.1] - 2026-01-06
9
19
 
10
20
  ### Changed
21
+
11
22
  - Updated documentation and GitHub repository links
12
23
 
13
24
  ## [1.0.0] - 2026-01-06
14
25
 
15
26
  ### Added
27
+
16
28
  - Initial release
17
29
  - `useJudgeme` hook with proper dependency arrays (fixing the infinite render loop bug from the original package)
18
30
  - All Judge.me widget components:
package/dist/index.d.mts CHANGED
@@ -6,6 +6,7 @@ declare global {
6
6
  SHOP_DOMAIN?: string;
7
7
  PLATFORM?: string;
8
8
  PUBLIC_TOKEN?: string;
9
+ LOCALE?: string;
9
10
  productData?: {
10
11
  id: string;
11
12
  title: string;
@@ -46,6 +47,14 @@ interface UseJudgemeConfig {
46
47
  * @default 500
47
48
  */
48
49
  delay?: number;
50
+ /**
51
+ * Locale code for Judge.me widget translations.
52
+ * Can be a full locale (e.g., 'fr-FR', 'fr-eu') or a simple language code ('fr').
53
+ * The hook will automatically extract the language code (first 2 characters)
54
+ * since Judge.me only supports simple language codes.
55
+ * @example 'fr', 'de', 'es', 'it', 'fr-FR', 'de-EU'
56
+ */
57
+ locale?: string;
49
58
  }
50
59
  interface JudgemePreviewBadgeProps {
51
60
  /**
@@ -132,6 +141,7 @@ interface JudgemeMedalsProps {
132
141
  * publicToken: 'your-public-token',
133
142
  * cdnHost: 'https://cdn.judge.me',
134
143
  * delay: 500, // optional, defaults to 500ms
144
+ * locale: 'fr-EU', // optional, supports full locale or simple code
135
145
  * });
136
146
  *
137
147
  * return <Outlet />;
@@ -143,8 +153,9 @@ interface JudgemeMedalsProps {
143
153
  * @param config.publicToken - Your Judge.me public token
144
154
  * @param config.cdnHost - Judge.me CDN host (usually 'https://cdn.judge.me')
145
155
  * @param config.delay - Delay before re-rendering widgets on route change (default: 500ms)
156
+ * @param config.locale - Locale for widget translations (e.g., 'fr', 'de', 'fr-EU'). Automatically extracts language code.
146
157
  */
147
- declare function useJudgeme({ shopDomain, publicToken, cdnHost, delay, }: UseJudgemeConfig): void;
158
+ declare function useJudgeme({ shopDomain, publicToken, cdnHost, delay, locale, }: UseJudgemeConfig): void;
148
159
 
149
160
  /**
150
161
  * Preview badge showing star rating for a product
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ declare global {
6
6
  SHOP_DOMAIN?: string;
7
7
  PLATFORM?: string;
8
8
  PUBLIC_TOKEN?: string;
9
+ LOCALE?: string;
9
10
  productData?: {
10
11
  id: string;
11
12
  title: string;
@@ -46,6 +47,14 @@ interface UseJudgemeConfig {
46
47
  * @default 500
47
48
  */
48
49
  delay?: number;
50
+ /**
51
+ * Locale code for Judge.me widget translations.
52
+ * Can be a full locale (e.g., 'fr-FR', 'fr-eu') or a simple language code ('fr').
53
+ * The hook will automatically extract the language code (first 2 characters)
54
+ * since Judge.me only supports simple language codes.
55
+ * @example 'fr', 'de', 'es', 'it', 'fr-FR', 'de-EU'
56
+ */
57
+ locale?: string;
49
58
  }
50
59
  interface JudgemePreviewBadgeProps {
51
60
  /**
@@ -132,6 +141,7 @@ interface JudgemeMedalsProps {
132
141
  * publicToken: 'your-public-token',
133
142
  * cdnHost: 'https://cdn.judge.me',
134
143
  * delay: 500, // optional, defaults to 500ms
144
+ * locale: 'fr-EU', // optional, supports full locale or simple code
135
145
  * });
136
146
  *
137
147
  * return <Outlet />;
@@ -143,8 +153,9 @@ interface JudgemeMedalsProps {
143
153
  * @param config.publicToken - Your Judge.me public token
144
154
  * @param config.cdnHost - Judge.me CDN host (usually 'https://cdn.judge.me')
145
155
  * @param config.delay - Delay before re-rendering widgets on route change (default: 500ms)
156
+ * @param config.locale - Locale for widget translations (e.g., 'fr', 'de', 'fr-EU'). Automatically extracts language code.
146
157
  */
147
- declare function useJudgeme({ shopDomain, publicToken, cdnHost, delay, }: UseJudgemeConfig): void;
158
+ declare function useJudgeme({ shopDomain, publicToken, cdnHost, delay, locale, }: UseJudgemeConfig): void;
148
159
 
149
160
  /**
150
161
  * Preview badge showing star rating for a product
package/dist/index.js CHANGED
@@ -40,12 +40,15 @@ function useJudgeme({
40
40
  shopDomain,
41
41
  publicToken,
42
42
  cdnHost,
43
- delay = 500
43
+ delay = 500,
44
+ locale
44
45
  }) {
46
+ const languageCode = locale ? locale.split("-")[0].toLowerCase() : void 0;
45
47
  const location = (0, import_react2.useLocation)();
46
48
  const lastPathnameRef = (0, import_react.useRef)("");
47
49
  const rerenderTimeoutRef = (0, import_react.useRef)(null);
48
50
  const isInitializedRef = (0, import_react.useRef)(false);
51
+ const initialRefreshDoneRef = (0, import_react.useRef)(false);
49
52
  const refreshWidgets = (0, import_react.useCallback)(() => {
50
53
  if (typeof window === "undefined") return;
51
54
  const attemptRefresh = (retriesLeft) => {
@@ -81,6 +84,9 @@ function useJudgeme({
81
84
  window.jdgm.SHOP_DOMAIN = shopDomain;
82
85
  window.jdgm.PLATFORM = "shopify";
83
86
  window.jdgm.PUBLIC_TOKEN = publicToken;
87
+ if (languageCode) {
88
+ window.jdgm.LOCALE = languageCode;
89
+ }
84
90
  fetch(`${cdnHost}/widget_preloader.js`).then((res) => {
85
91
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
86
92
  return res.text();
@@ -89,6 +95,7 @@ function useJudgeme({
89
95
  preloaderScript.innerText = `function jdgm_preloader(){${text}}`;
90
96
  document.head.appendChild(preloaderScript);
91
97
  console.log("Judge.me preloader script loaded, initializing widgets...");
98
+ initialRefreshDoneRef.current = true;
92
99
  refreshWidgets();
93
100
  }).catch((error) => {
94
101
  console.error("Judge.me: Failed to load scripts", error);
@@ -100,10 +107,14 @@ function useJudgeme({
100
107
  clearTimeout(rerenderTimeoutRef.current);
101
108
  }
102
109
  };
103
- }, [shopDomain, publicToken, cdnHost, refreshWidgets]);
110
+ }, [shopDomain, publicToken, cdnHost, languageCode, refreshWidgets]);
104
111
  (0, import_react.useEffect)(() => {
105
112
  if (typeof window === "undefined") return;
106
113
  const normalizedPathname = location.pathname.replace(/\/$/, "") || "/";
114
+ if (lastPathnameRef.current === "") {
115
+ lastPathnameRef.current = normalizedPathname;
116
+ return;
117
+ }
107
118
  if (lastPathnameRef.current === normalizedPathname) {
108
119
  return;
109
120
  }
package/dist/index.mjs CHANGED
@@ -6,12 +6,15 @@ function useJudgeme({
6
6
  shopDomain,
7
7
  publicToken,
8
8
  cdnHost,
9
- delay = 500
9
+ delay = 500,
10
+ locale
10
11
  }) {
12
+ const languageCode = locale ? locale.split("-")[0].toLowerCase() : void 0;
11
13
  const location = useLocation();
12
14
  const lastPathnameRef = useRef("");
13
15
  const rerenderTimeoutRef = useRef(null);
14
16
  const isInitializedRef = useRef(false);
17
+ const initialRefreshDoneRef = useRef(false);
15
18
  const refreshWidgets = useCallback(() => {
16
19
  if (typeof window === "undefined") return;
17
20
  const attemptRefresh = (retriesLeft) => {
@@ -47,6 +50,9 @@ function useJudgeme({
47
50
  window.jdgm.SHOP_DOMAIN = shopDomain;
48
51
  window.jdgm.PLATFORM = "shopify";
49
52
  window.jdgm.PUBLIC_TOKEN = publicToken;
53
+ if (languageCode) {
54
+ window.jdgm.LOCALE = languageCode;
55
+ }
50
56
  fetch(`${cdnHost}/widget_preloader.js`).then((res) => {
51
57
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
52
58
  return res.text();
@@ -55,6 +61,7 @@ function useJudgeme({
55
61
  preloaderScript.innerText = `function jdgm_preloader(){${text}}`;
56
62
  document.head.appendChild(preloaderScript);
57
63
  console.log("Judge.me preloader script loaded, initializing widgets...");
64
+ initialRefreshDoneRef.current = true;
58
65
  refreshWidgets();
59
66
  }).catch((error) => {
60
67
  console.error("Judge.me: Failed to load scripts", error);
@@ -66,10 +73,14 @@ function useJudgeme({
66
73
  clearTimeout(rerenderTimeoutRef.current);
67
74
  }
68
75
  };
69
- }, [shopDomain, publicToken, cdnHost, refreshWidgets]);
76
+ }, [shopDomain, publicToken, cdnHost, languageCode, refreshWidgets]);
70
77
  useEffect(() => {
71
78
  if (typeof window === "undefined") return;
72
79
  const normalizedPathname = location.pathname.replace(/\/$/, "") || "/";
80
+ if (lastPathnameRef.current === "") {
81
+ lastPathnameRef.current = normalizedPathname;
82
+ return;
83
+ }
73
84
  if (lastPathnameRef.current === normalizedPathname) {
74
85
  return;
75
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "judgeme-hydrogen-fixed",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Fixed version of @judgeme/shopify-hydrogen for Hydrogen/Oxygen. Fixes infinite refresh loops caused by installed.js and improper React hooks.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -33,7 +33,10 @@
33
33
  "reviews",
34
34
  "remix",
35
35
  "bug-fix",
36
- "refresh-loop-fix"
36
+ "refresh-loop-fix",
37
+ "i18n",
38
+ "locale",
39
+ "translations"
37
40
  ],
38
41
  "author": "Ben Goodman",
39
42
  "license": "MIT",