Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: error with quotes in search results (#20957)

Chariseff1e0a55ba3
diff --git a/package-lock.json b/package-lock.json
index 6390a7601b1..d06ea86a525 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -37971,6 +37971,7 @@
"react-copy-to-clipboard": "^5.1.0",
"react-countdown": "^2.3.5",
"react-day-picker": "^8.8.0",
+ "react-error-boundary": "^4.0.12",
"react-feather": "^2.0.10",
"react-hook-form": "^7.45.0",
"react-hot-toast": "^2.4.1",
diff --git a/packages/ui/package.json b/packages/ui/package.json
index 1a8609f3990..5f13fae221d 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -69,6 +69,7 @@
"react-copy-to-clipboard": "^5.1.0",
"react-countdown": "^2.3.5",
"react-day-picker": "^8.8.0",
+ "react-error-boundary": "^4.0.12",
"react-feather": "^2.0.10",
"react-hook-form": "^7.45.0",
"react-hot-toast": "^2.4.1",
diff --git a/packages/ui/src/components/Command/Command.utils.tsx b/packages/ui/src/components/Command/Command.utils.tsx
index a8d64b35430..e9f29c78f4a 100644
--- a/packages/ui/src/components/Command/Command.utils.tsx
+++ b/packages/ui/src/components/Command/Command.utils.tsx
@@ -1,5 +1,7 @@
import { Command as CommandPrimitive } from 'cmdk'
import * as React from 'react'
+import { ErrorBoundary } from 'react-error-boundary'
+import { IconAlertTriangle } from 'ui'
import { cn } from './../../lib/utils'
@@ -8,6 +10,7 @@ import { LoadingLine } from '../LoadingLine/LoadingLine'
import { Modal } from '../Modal'
import { ModalProps } from '../Modal/Modal'
import { useCommandMenu } from './CommandMenuProvider'
+import { Button } from '../Button'
type CommandPrimitiveElement = React.ElementRef<typeof CommandPrimitive>
type CommandPrimitiveProps = React.ComponentPropsWithoutRef<typeof CommandPrimitive>
@@ -21,6 +24,10 @@ export const copyToClipboard = (str: string, callback = () => {}) => {
}
}
+export function escapeDoubleQuotes(str: string) {
+ return str.replaceAll('"', '\\"')
+}
+
export const Command = React.forwardRef<CommandPrimitiveElement, CommandPrimitiveProps>(
({ className, ...props }, ref) => (
<CommandPrimitive
@@ -33,6 +40,23 @@ export const Command = React.forwardRef<CommandPrimitiveElement, CommandPrimitiv
Command.displayName = CommandPrimitive.displayName
+export function CommandError({ resetErrorBoundary }: { resetErrorBoundary: () => void }) {
+ return (
+ <div className={cn('min-h-64', 'flex items-center justify-center')}>
+ <div className="p-10 flex flex-col items-center gap-6 mt-4">
+ <IconAlertTriangle strokeWidth={1.5} size={40} />
+ <p className="text-lg text-center">
+ Sorry, looks like we&apos;re having some issues with the command menu!
+ </p>
+ <p className="text-sm text-center">Please try again in a bit.</p>
+ <Button size="tiny" type="secondary" onClick={resetErrorBoundary}>
+ Try again?
+ </Button>
+ </div>
+ </div>
+ )
+}
+
export interface CommandDialogProps extends ModalProps {
onKeyDown?: KeyboardEventHandler<HTMLDivElement>
page?: number | string
@@ -59,19 +83,21 @@ export const CommandDialog = ({ children, onKeyDown, page, ...props }: CommandDi
animateBounce ? 'scale-[101.5%]' : 'scale-100'
)}
>
- <Command
- className={[
- '[&_[cmdk-group]]:px-2 [&_[cmdk-group]]:!bg-transparent [&_[cmdk-group-heading]]:!bg-transparent [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-border-stronger [&_[cmdk-input]]:h-12',
- '[&_[cmdk-item]_svg]:h-5',
- '[&_[cmdk-item]_svg]:w-5',
- '[&_[cmdk-input-wrapper]_svg]:h-5',
- '[&_[cmdk-input-wrapper]_svg]:w-5',
-
- '[&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0',
- ].join(' ')}
- >
- {children}
- </Command>
+ <ErrorBoundary FallbackComponent={CommandError}>
+ <Command
+ className={[
+ '[&_[cmdk-group]]:px-2 [&_[cmdk-group]]:!bg-transparent [&_[cmdk-group-heading]]:!bg-transparent [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-border-stronger [&_[cmdk-input]]:h-12',
+ '[&_[cmdk-item]_svg]:h-5',
+ '[&_[cmdk-item]_svg]:w-5',
+ '[&_[cmdk-input-wrapper]_svg]:h-5',
+ '[&_[cmdk-input-wrapper]_svg]:w-5',
+
+ '[&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0',
+ ].join(' ')}
+ >
+ {children}
+ </Command>
+ </ErrorBoundary>
</Modal>
)
}
diff --git a/packages/ui/src/components/Command/DocsSearch.tsx b/packages/ui/src/components/Command/DocsSearch.tsx
index fa8869dec2e..82ebc9ec534 100644
--- a/packages/ui/src/components/Command/DocsSearch.tsx
+++ b/packages/ui/src/components/Command/DocsSearch.tsx
@@ -14,7 +14,13 @@ import {
IconSearch,
useCommandMenu,
} from 'ui'
-import { CommandGroup, CommandItem, CommandLabel, TextHighlighter } from './Command.utils'
+import {
+ CommandGroup,
+ CommandItem,
+ CommandLabel,
+ TextHighlighter,
+ escapeDoubleQuotes,
+} from './Command.utils'
import { useRouter } from 'next/router'
const NUMBER_SOURCES = 2
@@ -168,8 +174,8 @@ function reducer(state: SearchState, action: Action): SearchState {
'results' in state
? state.results
: 'staleResults' in state
- ? state.staleResults
- : [],
+ ? state.staleResults
+ : [],
}
}
return allSourcesLoaded
@@ -410,12 +416,12 @@ const DocsSearch = () => {
<CommandGroup
heading=""
key={`${page.path}-group`}
- value={`${page.title}-group-index-${i}`}
+ value={`${escapeDoubleQuotes(page.title)}-group-index-${i}`}
forceMount={true}
>
<CommandItem
key={`${page.path}-item`}
- value={`${page.title}-item-index-${i}`}
+ value={`${escapeDoubleQuotes(page.title)}-item-index-${i}`}
type="block-link"
onSelect={() => {
openLink(page.type, formatPageUrl(page))
@@ -450,7 +456,9 @@ const DocsSearch = () => {
openLink(page.type, formatSectionUrl(page, section))
}}
key={`${page.path}__${section.heading}-item`}
- value={`${page.title}__${section.heading}-item-index-${i}`}
+ value={`${escapeDoubleQuotes(
+ page.title
+ )}__${escapeDoubleQuotes(section.heading)}-item-index-${i}`}
forceMount={true}
type="block-link"
>