@@ -5,11 +5,9 @@ import { useRouter } from "next/navigation"
5
5
6
6
import { cn } from "@/lib/utils/cn"
7
7
8
- import { AB_TEST_COOKIE_PREFIX } from "@/lib/constants"
9
-
10
8
import { Button } from "../ui/buttons/Button"
11
9
12
- import { clearABTestCookie , forceABTestVariant } from "@/lib/ab-testing/actions"
10
+ import { forceABTestVariant } from "@/lib/ab-testing/actions"
13
11
import { ABTestAssignment } from "@/lib/ab-testing/types"
14
12
15
13
type ABTestDebugPanelProps = {
@@ -33,28 +31,11 @@ export function ABTestDebugPanel({
33
31
setLocalAssignment ( currentAssignment )
34
32
} , [ currentAssignment ] )
35
33
36
- const cookieName = AB_TEST_COOKIE_PREFIX + testKey
37
- // Check if cookie exists client-side and set fallback if needed
38
- useEffect ( ( ) => {
39
- if ( currentAssignment ) {
40
- const cookieExists = document . cookie . includes ( cookieName )
41
-
42
- if ( ! cookieExists ) {
43
- console . log ( `[AB Test Debug] Setting fallback cookie for ${ testKey } ` )
44
- document . cookie = `${ cookieName } =${ JSON . stringify ( currentAssignment ) } ; max-age=${ 60 * 60 * 24 * 30 } ; path=/; samesite=lax`
45
- }
46
- }
47
- } , [ cookieName , currentAssignment , testKey ] )
48
-
49
34
const forceVariant = async ( variantName : string ) => {
50
35
try {
51
36
const newAssignment = await forceABTestVariant ( testKey , variantName )
52
37
setLocalAssignment ( newAssignment )
53
38
54
- // Fallback: Set cookie client-side if server action doesn't persist
55
- document . cookie = `${ cookieName } =${ JSON . stringify ( newAssignment ) } ; max-age=${ 60 * 60 * 24 * 30 } ; path=/; samesite=lax`
56
-
57
- // Use transition for smoother updates without full refresh
58
39
startTransition ( ( ) => {
59
40
router . refresh ( )
60
41
} )
@@ -63,41 +44,13 @@ export function ABTestDebugPanel({
63
44
}
64
45
}
65
46
66
- const clearCookie = async ( ) => {
67
- try {
68
- await clearABTestCookie ( testKey )
69
-
70
- // Fallback: Clear cookie client-side as well
71
- document . cookie = `${ cookieName } =; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`
72
-
73
- setLocalAssignment ( null )
74
- // Use transition for smoother updates without full refresh
75
- startTransition ( ( ) => {
76
- router . refresh ( )
77
- } )
78
- } catch ( error ) {
79
- console . error ( "Failed to clear cookie:" , error )
80
- }
81
- }
82
-
83
- const resetAllTests = ( ) => {
84
- // Clear all AB test cookies and reload page
85
- document . cookie . split ( ";" ) . forEach ( ( cookie ) => {
86
- const [ name ] = cookie . split ( "=" )
87
- if ( name . trim ( ) . startsWith ( AB_TEST_COOKIE_PREFIX ) ) {
88
- document . cookie = `${ name . trim ( ) } =; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`
89
- }
90
- } )
91
- window . location . reload ( )
92
- }
93
-
94
47
return (
95
- < div className = "fixed bottom-5 right-5 z-sticky rounded-lg border-2 bg-background-low p-2.5 font-mono text-xs" >
48
+ < div className = "fixed bottom-5 right-5 z-modal rounded-lg border-2 bg-background-low p-2.5 font-mono text-xs" >
96
49
< Button
97
50
onClick = { ( ) => setIsOpen ( ! isOpen ) }
98
51
className = "w-full cursor-pointer rounded border-none bg-accent-a px-2.5 py-1 font-semibold text-white hover:bg-accent-a-hover"
99
52
>
100
- 🧪 AB Test Debug
53
+ 🧪 AB Test Switcher
101
54
</ Button >
102
55
103
56
{ isOpen && (
@@ -111,16 +64,9 @@ export function ABTestDebugPanel({
111
64
< span className = "ml-2 text-xs text-gray-500" > Loading...</ span >
112
65
) }
113
66
</ div >
114
- < div className = "mt-1 text-2xs" >
115
- < strong > Cookie:</ strong > { " " }
116
- { typeof window !== "undefined" &&
117
- document . cookie . includes ( AB_TEST_COOKIE_PREFIX + testKey )
118
- ? "✓ Set"
119
- : "✗ Missing" }
120
- </ div >
121
67
< div className = "mt-2.5" >
122
68
< div >
123
- < strong > Force Variant :</ strong >
69
+ < strong > Force variant :</ strong >
124
70
</ div >
125
71
{ availableVariants . map ( ( variant ) => (
126
72
< Button
@@ -141,30 +87,6 @@ export function ABTestDebugPanel({
141
87
{ variant }
142
88
</ Button >
143
89
) ) }
144
- < div className = "mt-2.5 flex gap-1" >
145
- < Button
146
- onClick = { clearCookie }
147
- disabled = { isPending }
148
- className = { cn (
149
- "flex-1 rounded border-none bg-warning px-2 py-1 text-xs text-black hover:bg-warning-dark" ,
150
- isPending ? "cursor-not-allowed opacity-60" : "cursor-pointer"
151
- ) }
152
- title = "Clear this test's cookie and get new random assignment"
153
- >
154
- 🔄 Reset Test
155
- </ Button >
156
- < Button
157
- onClick = { resetAllTests }
158
- disabled = { isPending }
159
- className = { cn (
160
- "flex-1 rounded border-none bg-error px-2 py-1 text-xs text-white hover:bg-error-dark" ,
161
- isPending ? "cursor-not-allowed opacity-60" : "cursor-pointer"
162
- ) }
163
- title = "Clear all AB test cookies and reload page"
164
- >
165
- 🗑️ Reset All
166
- </ Button >
167
- </ div >
168
90
</ div >
169
91
</ div >
170
92
) }
0 commit comments