@alpaca-headless/alpaca-headless-nextjs 1.0.4246 → 1.0.4255
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,72 +1,27 @@
|
|
|
1
1
|
import { useRouter, useSearchParams } from "next/navigation";
|
|
2
|
-
import { useEffect
|
|
2
|
+
import { useEffect } from "react";
|
|
3
3
|
import uuid from "react-uuid";
|
|
4
|
-
// Helper for consistent logging with timestamps
|
|
5
|
-
const log = (message, data) => {
|
|
6
|
-
const timestamp = new Date().toISOString();
|
|
7
|
-
if (data !== undefined) {
|
|
8
|
-
console.log(`[HEADLESS ${timestamp}] ${message}`, data);
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
console.log(`[HEADLESS ${timestamp}] ${message}`);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
4
|
const useExposeRefreshFunction = () => {
|
|
15
5
|
const router = useRouter();
|
|
16
6
|
const searchParams = useSearchParams();
|
|
17
|
-
const [refreshStart, setRefreshStart] = useState();
|
|
18
|
-
const mountCountRef = useRef(0);
|
|
19
|
-
const instanceIdRef = useRef(Math.random().toString(36).substring(7));
|
|
20
|
-
log(`useExposeRefreshFunction hook called, instance: ${instanceIdRef.current}`);
|
|
21
7
|
useEffect(() => {
|
|
22
|
-
mountCountRef.current++;
|
|
23
|
-
const mountId = mountCountRef.current;
|
|
24
|
-
log(`useEffect[router] RUNNING - mount #${mountId}, instance: ${instanceIdRef.current}`);
|
|
25
|
-
log(`Current window.requestRefresh before set:`, typeof window.requestRefresh);
|
|
26
|
-
log(`window.parent === window:`, window.parent === window);
|
|
27
8
|
// Expose the refresh function to the parent window
|
|
28
9
|
window.requestRefresh = (newUri) => {
|
|
29
|
-
log(`requestRefresh CALLED with:`, newUri);
|
|
30
|
-
log(`Called from mount #${mountId}, instance: ${instanceIdRef.current}`);
|
|
31
10
|
if (!newUri) {
|
|
32
11
|
const uri = new URL(window.location.href);
|
|
33
12
|
uri.searchParams.set("edit_rev", uuid().toString());
|
|
34
13
|
newUri = uri.toString();
|
|
35
14
|
}
|
|
36
|
-
log(`router.replace() about to be called with:`, newUri);
|
|
37
15
|
router.replace(newUri, { scroll: false });
|
|
38
|
-
setRefreshStart(performance.now());
|
|
39
|
-
log(`router.replace() completed`);
|
|
40
16
|
return true; // Indicate the function executed successfully
|
|
41
17
|
};
|
|
42
|
-
log(`window.requestRefresh SET, typeof:`, typeof window.requestRefresh);
|
|
43
|
-
// Notify parent that integration is ready
|
|
44
|
-
if (window.parent !== window) {
|
|
45
|
-
log(`Sending integration-ready postMessage to parent`);
|
|
46
|
-
try {
|
|
47
|
-
window.parent.postMessage({ type: "integration-ready" }, "*");
|
|
48
|
-
log(`integration-ready postMessage SENT successfully`);
|
|
49
|
-
}
|
|
50
|
-
catch (e) {
|
|
51
|
-
log(`integration-ready postMessage FAILED:`, e);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
log(`NOT in iframe (window.parent === window), skipping integration-ready`);
|
|
56
|
-
}
|
|
57
18
|
// Optionally clean up when the component unmounts
|
|
58
19
|
return () => {
|
|
59
|
-
log(`useEffect[router] CLEANUP - mount #${mountId}, instance: ${instanceIdRef.current}`);
|
|
60
|
-
log(`Deleting window.requestRefresh`);
|
|
61
20
|
delete window.requestRefresh;
|
|
62
|
-
log(`window.requestRefresh after delete:`, typeof window.requestRefresh);
|
|
63
21
|
};
|
|
64
22
|
}, [router]);
|
|
65
23
|
useEffect(() => {
|
|
66
|
-
|
|
67
|
-
const duration = performance.now() - refreshStart;
|
|
68
|
-
log(`Refresh complete in ${duration}ms`);
|
|
69
|
-
}
|
|
24
|
+
// Refresh tracking logic (debug logging removed)
|
|
70
25
|
}, [searchParams]);
|
|
71
26
|
return null; // This hook doesn't render anything
|
|
72
27
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alpaca-headless/alpaca-headless-nextjs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4255",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Alpaca Headless",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"typescript": "^5"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@alpaca-headless/alpaca-headless": "^1.0.
|
|
55
|
+
"@alpaca-headless/alpaca-headless": "^1.0.4255",
|
|
56
56
|
"axios": "^1.8.1",
|
|
57
57
|
"https-proxy-agent": "^7.0.4",
|
|
58
58
|
"next": "^14.2.4",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useRouter, useSearchParams } from "next/navigation";
|
|
2
|
-
import { useEffect
|
|
2
|
+
import { useEffect } from "react";
|
|
3
3
|
import uuid from "react-uuid";
|
|
4
4
|
|
|
5
5
|
declare global {
|
|
@@ -8,89 +8,32 @@ declare global {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
// Helper for consistent logging with timestamps
|
|
12
|
-
const log = (message: string, data?: any) => {
|
|
13
|
-
const timestamp = new Date().toISOString();
|
|
14
|
-
if (data !== undefined) {
|
|
15
|
-
console.log(`[HEADLESS ${timestamp}] ${message}`, data);
|
|
16
|
-
} else {
|
|
17
|
-
console.log(`[HEADLESS ${timestamp}] ${message}`);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
11
|
const useExposeRefreshFunction = () => {
|
|
22
12
|
const router = useRouter();
|
|
23
13
|
const searchParams = useSearchParams();
|
|
24
|
-
const [refreshStart, setRefreshStart] = useState<number>();
|
|
25
|
-
const mountCountRef = useRef(0);
|
|
26
|
-
const instanceIdRef = useRef(Math.random().toString(36).substring(7));
|
|
27
|
-
|
|
28
|
-
log(
|
|
29
|
-
`useExposeRefreshFunction hook called, instance: ${instanceIdRef.current}`
|
|
30
|
-
);
|
|
31
14
|
|
|
32
15
|
useEffect(() => {
|
|
33
|
-
mountCountRef.current++;
|
|
34
|
-
const mountId = mountCountRef.current;
|
|
35
|
-
log(
|
|
36
|
-
`useEffect[router] RUNNING - mount #${mountId}, instance: ${instanceIdRef.current}`
|
|
37
|
-
);
|
|
38
|
-
log(
|
|
39
|
-
`Current window.requestRefresh before set:`,
|
|
40
|
-
typeof window.requestRefresh
|
|
41
|
-
);
|
|
42
|
-
log(`window.parent === window:`, window.parent === window);
|
|
43
|
-
|
|
44
16
|
// Expose the refresh function to the parent window
|
|
45
17
|
window.requestRefresh = (newUri?: string) => {
|
|
46
|
-
log(`requestRefresh CALLED with:`, newUri);
|
|
47
|
-
log(`Called from mount #${mountId}, instance: ${instanceIdRef.current}`);
|
|
48
18
|
if (!newUri) {
|
|
49
19
|
const uri = new URL(window.location.href);
|
|
50
20
|
uri.searchParams.set("edit_rev", uuid().toString());
|
|
51
21
|
newUri = uri.toString();
|
|
52
22
|
}
|
|
53
23
|
|
|
54
|
-
log(`router.replace() about to be called with:`, newUri);
|
|
55
24
|
router.replace(newUri, { scroll: false });
|
|
56
|
-
|
|
57
|
-
log(`router.replace() completed`);
|
|
25
|
+
|
|
58
26
|
return true; // Indicate the function executed successfully
|
|
59
27
|
};
|
|
60
28
|
|
|
61
|
-
log(`window.requestRefresh SET, typeof:`, typeof window.requestRefresh);
|
|
62
|
-
|
|
63
|
-
// Notify parent that integration is ready
|
|
64
|
-
if (window.parent !== window) {
|
|
65
|
-
log(`Sending integration-ready postMessage to parent`);
|
|
66
|
-
try {
|
|
67
|
-
window.parent.postMessage({ type: "integration-ready" }, "*");
|
|
68
|
-
log(`integration-ready postMessage SENT successfully`);
|
|
69
|
-
} catch (e) {
|
|
70
|
-
log(`integration-ready postMessage FAILED:`, e);
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
log(
|
|
74
|
-
`NOT in iframe (window.parent === window), skipping integration-ready`
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
29
|
// Optionally clean up when the component unmounts
|
|
79
30
|
return () => {
|
|
80
|
-
log(
|
|
81
|
-
`useEffect[router] CLEANUP - mount #${mountId}, instance: ${instanceIdRef.current}`
|
|
82
|
-
);
|
|
83
|
-
log(`Deleting window.requestRefresh`);
|
|
84
31
|
delete window.requestRefresh;
|
|
85
|
-
log(`window.requestRefresh after delete:`, typeof window.requestRefresh);
|
|
86
32
|
};
|
|
87
33
|
}, [router]);
|
|
88
34
|
|
|
89
35
|
useEffect(() => {
|
|
90
|
-
|
|
91
|
-
const duration = performance.now() - refreshStart;
|
|
92
|
-
log(`Refresh complete in ${duration}ms`);
|
|
93
|
-
}
|
|
36
|
+
// Refresh tracking logic (debug logging removed)
|
|
94
37
|
}, [searchParams]);
|
|
95
38
|
|
|
96
39
|
return null; // This hook doesn't render anything
|