-
Notifications
You must be signed in to change notification settings - Fork 14
fix: coordinate the first fetch in guide toolbar v2 and guide client via readyToTarget #942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thomaswhyyou
merged 4 commits into
main
from
thomas-kno-12539-toolbar-fix-not-authenticated-error-in-new-sdk-version-2
Apr 9, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "@knocklabs/react-core": patch | ||
| "@knocklabs/client": patch | ||
| "@knocklabs/react": patch | ||
| --- | ||
|
|
||
| [Guides] Use `readyToTarget` to coordinate fetching guides in guide toolbar v2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { | |
| GuideActivationUrlRuleData, | ||
| GuideData, | ||
| GuideGroupData, | ||
| KnockGuide, | ||
| KnockGuideActivationUrlPattern, | ||
| SelectFilterParams, | ||
| StoreState, | ||
|
|
@@ -225,3 +226,40 @@ export const predicateUrlPatterns = ( | |
| } | ||
| }, predicateDefault); | ||
| }; | ||
|
|
||
| // Use this param to start Toolbar v2 and enter into a debugging session when | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just moved, not new. |
||
| // it is present and set to true. | ||
| const TOOLBAR_QUERY_PARAM = "knock_guide_toolbar"; | ||
|
|
||
| // Optional, when present pin/focus on this guide. | ||
| const GUIDE_KEY_PARAM = "focused_guide_key"; | ||
|
|
||
| export type ToolbarV2RunConfig = { | ||
| isVisible: boolean; | ||
| focusedGuideKeys?: Record<KnockGuide["key"], true>; | ||
| }; | ||
|
|
||
| export const getToolbarRunConfigFromUrl = (): ToolbarV2RunConfig => { | ||
| const fallback = { isVisible: false }; | ||
|
|
||
| if (typeof window === "undefined" || !window.location) { | ||
| return fallback; | ||
| } | ||
|
|
||
| const urlSearchParams = new URLSearchParams(window.location.search); | ||
| const toolbarParamValue = urlSearchParams.get(TOOLBAR_QUERY_PARAM); | ||
| const guideKeyParamValue = urlSearchParams.get(GUIDE_KEY_PARAM); | ||
|
|
||
| if (toolbarParamValue === null) { | ||
| return fallback; | ||
| } | ||
|
|
||
| const config: ToolbarV2RunConfig = { | ||
| isVisible: toolbarParamValue === "true", | ||
| }; | ||
| if (guideKeyParamValue) { | ||
| config.focusedGuideKeys = { [guideKeyParamValue]: true }; | ||
| } | ||
|
|
||
| return config; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import { KnockGuideClient } from "@knocklabs/client"; | ||
| import { useGuideContext } from "@knocklabs/react-core"; | ||
| import { Button } from "@telegraph/button"; | ||
| import { Icon } from "@telegraph/icon"; | ||
|
|
@@ -22,7 +23,7 @@ import "../styles.css"; | |
| import { FocusChin } from "./FocusChin"; | ||
| import { GuideContextDetails } from "./GuideContextDetails"; | ||
| import { GuideRow } from "./GuideRow"; | ||
| import { DisplayOption, getRunConfig, sharedTooltipProps } from "./helpers"; | ||
| import { DisplayOption, sharedTooltipProps } from "./helpers"; | ||
| import { useDraggable } from "./useDraggable"; | ||
| import { | ||
| InspectionResultOk, | ||
|
|
@@ -84,12 +85,18 @@ const filterGuides = ( | |
| }); | ||
| }; | ||
|
|
||
| export const V2 = () => { | ||
| type Props = { | ||
| readyToTarget: boolean; | ||
| }; | ||
|
|
||
| export const V2 = ({ readyToTarget }: Props) => { | ||
| const { client } = useGuideContext(); | ||
|
|
||
| const [displayOption, setDisplayOption] = | ||
| React.useState<DisplayOption>("only-active"); | ||
| const [runConfig, setRunConfig] = React.useState(() => getRunConfig()); | ||
| const [runConfig, setRunConfig] = React.useState(() => | ||
| KnockGuideClient.getToolbarRunConfigFromUrl(), | ||
| ); | ||
| const [isCollapsed, setIsCollapsed] = React.useState(false); | ||
| const [isContextPanelOpen, setIsContextPanelOpen] = React.useState(false); | ||
|
|
||
|
|
@@ -104,7 +111,7 @@ export const V2 = () => { | |
| React.useEffect(() => { | ||
| const { isVisible = false, focusedGuideKeys = {} } = runConfig || {}; | ||
| const isDebugging = client.store.state.debug?.debugging; | ||
| if (isVisible && !isDebugging) { | ||
| if (isVisible && !isDebugging && readyToTarget) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the main change: We check if |
||
| client.setDebug({ focusedGuideKeys }); | ||
|
|
||
| // If focused, switch to all guides so you can see in the list. | ||
|
|
@@ -116,7 +123,7 @@ export const V2 = () => { | |
| return () => { | ||
| client.unsetDebug(); | ||
| }; | ||
| }, [runConfig, client, setDisplayOption]); | ||
| }, [readyToTarget, runConfig, client, setDisplayOption]); | ||
|
|
||
| // Toggle collapsed state with Ctrl + . | ||
| React.useEffect(() => { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #943.