@@ -64,14 +64,6 @@ const DEFAULT_COUNTER_INCREMENT_INTERVAL = 30 * 1000; // in milliseconds
6464// Maximum number of retry attempts for channel subscription
6565const SUBSCRIBE_RETRY_LIMIT = 3 ;
6666
67- // Debug query param keys
68- export const DEBUG_QUERY_PARAMS = {
69- GUIDE_KEY : "knock_guide_key" ,
70- PREVIEW_SESSION_ID : "knock_preview_session_id" ,
71- } ;
72-
73- const DEBUG_STORAGE_KEY = "knock_guide_debug" ;
74-
7567// Return the global window object if defined, so to safely guard against SSR.
7668const checkForWindow = ( ) => {
7769 if ( typeof window !== "undefined" ) {
@@ -82,76 +74,6 @@ const checkForWindow = () => {
8274export const guidesApiRootPath = ( userId : string | undefined | null ) =>
8375 `/v1/users/${ userId } /guides` ;
8476
85- // Detect debug params from URL or local storage
86- const detectDebugParams = ( ) : DebugState => {
87- const win = checkForWindow ( ) ;
88- if ( ! win || ! win . location ) {
89- return { forcedGuideKey : null , previewSessionId : null } ;
90- }
91-
92- const urlParams = new URLSearchParams ( win . location . search ) ;
93- const urlGuideKey = urlParams . get ( DEBUG_QUERY_PARAMS . GUIDE_KEY ) ;
94- const urlPreviewSessionId = urlParams . get (
95- DEBUG_QUERY_PARAMS . PREVIEW_SESSION_ID ,
96- ) ;
97-
98- // If URL params exist, persist them to localStorage and return them
99- if ( urlGuideKey || urlPreviewSessionId ) {
100- if ( win . localStorage ) {
101- try {
102- const debugState = {
103- forcedGuideKey : urlGuideKey ,
104- previewSessionId : urlPreviewSessionId ,
105- } ;
106- win . localStorage . setItem ( DEBUG_STORAGE_KEY , JSON . stringify ( debugState ) ) ;
107- } catch {
108- // Silently fail in privacy mode
109- }
110- }
111- return {
112- forcedGuideKey : urlGuideKey ,
113- previewSessionId : urlPreviewSessionId ,
114- } ;
115- }
116-
117- // Check local storage if no URL params
118- let storedGuideKey = null ;
119- let storedPreviewSessionId = null ;
120-
121- if ( win . localStorage ) {
122- try {
123- const storedDebugState = win . localStorage . getItem ( DEBUG_STORAGE_KEY ) ;
124- if ( storedDebugState ) {
125- const parsedDebugState = safeJsonParseDebugParams ( storedDebugState ) ;
126- storedGuideKey = parsedDebugState . forcedGuideKey ;
127- storedPreviewSessionId = parsedDebugState . previewSessionId ;
128- }
129- } catch {
130- // Silently fail in privacy mode
131- }
132- }
133-
134- return {
135- forcedGuideKey : storedGuideKey ,
136- previewSessionId : storedPreviewSessionId ,
137- } ;
138- } ;
139-
140- const safeJsonParseDebugParams = ( value : string ) : DebugState => {
141- try {
142- const parsed = JSON . parse ( value ) ;
143- return {
144- forcedGuideKey : parsed ?. forcedGuideKey ?? null ,
145- previewSessionId : parsed ?. previewSessionId ?? null ,
146- } ;
147- } catch {
148- return {
149- forcedGuideKey : null ,
150- previewSessionId : null ,
151- } ;
152- }
153- } ;
154-
15577type SelectQueryMetadata = {
15678 limit : SelectQueryLimit ;
15779 opts : SelectGuideOpts ;
@@ -295,15 +217,11 @@ export class KnockGuideClient {
295217 ) {
296218 const {
297219 trackLocationFromWindow = true ,
298- // TODO(KNO-11523): Remove once we ship guide toolbar v2, and offload as
299- // much debugging specific logic and responsibilities to toolbar.
300- trackDebugParams = false ,
301220 throttleCheckInterval = DEFAULT_COUNTER_INCREMENT_INTERVAL ,
302221 } = options ;
303222 const win = checkForWindow ( ) ;
304223
305224 const location = trackLocationFromWindow ? win ?. location ?. href : undefined ;
306- const debug = trackDebugParams ? detectDebugParams ( ) : undefined ;
307225
308226 this . store = new Store < StoreState > ( {
309227 guideGroups : [ ] ,
@@ -315,7 +233,6 @@ export class KnockGuideClient {
315233 location,
316234 // Increment to update the state store and trigger re-selection.
317235 counter : 0 ,
318- debug,
319236 } ) ;
320237
321238 // In server environments we might not have a socket connection.
@@ -560,45 +477,6 @@ export class KnockGuideClient {
560477 } ) ;
561478 }
562479
563- exitDebugMode ( ) {
564- this . knock . log ( "[Guide] Exiting debug mode" ) ;
565-
566- // Clear localStorage debug params
567- const win = checkForWindow ( ) ;
568- if ( win ?. localStorage ) {
569- try {
570- win . localStorage . removeItem ( DEBUG_STORAGE_KEY ) ;
571- } catch {
572- // Silently fail in privacy mode
573- }
574- }
575-
576- // Clear debug state from store
577- this . store . setState ( ( state ) => ( {
578- ...state ,
579- debug : {
580- forcedGuideKey : null ,
581- previewSessionId : null ,
582- focusedGuideKeys : { } ,
583- } ,
584- previewGuides : { } , // Clear preview guides when exiting debug mode
585- } ) ) ;
586-
587- // Remove URL query params if present
588- // Only update the URL if params need to be cleared to avoid unnecessary navigations
589- if ( win ?. location ) {
590- const url = new URL ( win . location . href ) ;
591- if (
592- url . searchParams . has ( DEBUG_QUERY_PARAMS . GUIDE_KEY ) ||
593- url . searchParams . has ( DEBUG_QUERY_PARAMS . PREVIEW_SESSION_ID )
594- ) {
595- url . searchParams . delete ( DEBUG_QUERY_PARAMS . GUIDE_KEY ) ;
596- url . searchParams . delete ( DEBUG_QUERY_PARAMS . PREVIEW_SESSION_ID ) ;
597- win . location . href = url . toString ( ) ;
598- }
599- }
600- }
601-
602480 setDebug ( debugOpts ?: Omit < DebugState , "debugging" > ) {
603481 this . knock . log ( "[Guide] .setDebug()" ) ;
604482
@@ -1399,43 +1277,9 @@ export class KnockGuideClient {
13991277
14001278 this . knock . log ( `[Guide] Detected a location change: ${ href } ` ) ;
14011279
1402- if ( ! this . options . trackDebugParams ) {
1403- this . setLocation ( href ) ;
1404- return ;
1405- }
1406-
1407- // TODO(KNO-11523): Remove below once we ship toolbar v2.
1408-
1409- // If entering debug mode, fetch all guides.
1410- const currentDebugParams = this . store . state . debug || { } ;
1411- const newDebugParams = detectDebugParams ( ) ;
1412-
1413- this . setLocation ( href , { debug : newDebugParams } ) ;
1414-
1415- // If debug state has changed, refetch guides and resubscribe to the websocket channel
1416- const debugStateChanged = this . checkDebugStateChanged (
1417- currentDebugParams ,
1418- newDebugParams ,
1419- ) ;
1420-
1421- if ( debugStateChanged ) {
1422- this . knock . log (
1423- `[Guide] Debug state changed, refetching guides and resubscribing to the websocket channel` ,
1424- ) ;
1425- this . fetch ( ) ;
1426- this . subscribe ( ) ;
1427- }
1280+ this . setLocation ( href ) ;
14281281 } ;
14291282
1430- // Returns whether debug params have changed. For guide key, we only check
1431- // presence since the exact value has no impact on fetch/subscribe
1432- private checkDebugStateChanged ( a : DebugState , b : DebugState ) : boolean {
1433- return (
1434- Boolean ( a . forcedGuideKey ) !== Boolean ( b . forcedGuideKey ) ||
1435- a . previewSessionId !== b . previewSessionId
1436- ) ;
1437- }
1438-
14391283 private listenForLocationChangesFromWindow ( ) {
14401284 const win = checkForWindow ( ) ;
14411285 if ( win ?. history && win ?. addEventListener ) {
0 commit comments