Skip to content

Commit 1c150df

Browse files
authored
fix(links): keep long searches within the list limit (#9702)
A Links search over 200 characters failed client validation and showed the raw error. Cap it in the input and in the URL parser, the way People does, so a deep link stays valid too.
1 parent 6acfeb3 commit 1c150df

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

‎apps/sim/app/o/[organizationId]/links/search-params.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import { createSerializer, parseAsString } from 'nuqs/server'
2-
import { SIM_LINK_SORTS } from '@/lib/sim-links/validation'
1+
import { truncateAtCodePoint } from '@sim/utils/string'
2+
import { createParser, createSerializer, parseAsString } from 'nuqs/server'
3+
import { SIM_LINK_SEARCH_MAX_LENGTH, SIM_LINK_SORTS } from '@/lib/sim-links/validation'
34
import { createSortParams } from '@/lib/url-state'
45

6+
const boundedSearch = (value: string) => truncateAtCodePoint(value, SIM_LINK_SEARCH_MAX_LENGTH, '')
7+
58
/**
69
* `create` opens the new-link editor, prefilled with its value as the name. `search` filters by
710
* name, destination, or description.
811
*/
912
export const simLinksParsers = {
1013
create: parseAsString,
11-
search: parseAsString.withDefault(''),
14+
search: createParser({ parse: boundedSearch, serialize: boundedSearch }).withDefault(''),
1215
} as const
1316

1417
export const serializeSimLinkView = createSerializer(simLinksParsers)

‎apps/sim/app/o/[organizationId]/links/sim-links.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useQueryStates } from 'nuqs'
88
import type { SimLink } from '@/lib/api/contracts/sim-links'
99
import { useDeploymentShape } from '@/lib/core/config/deployment-shape'
1010
import { simLinkPath, simLinkUrl } from '@/lib/navigation/paths'
11-
import { toSimLinkName } from '@/lib/sim-links/validation'
11+
import { SIM_LINK_SEARCH_MAX_LENGTH, toSimLinkName } from '@/lib/sim-links/validation'
1212
import { SEARCH_DEBOUNCE_MS } from '@/lib/url-state'
1313
import {
1414
INSTALL_EXTENSION_ACTION,
@@ -132,6 +132,7 @@ export function SimLinks({ organizationId }: SimLinksProps) {
132132

133133
const searchConfig: SearchConfig = {
134134
value: search,
135+
maxLength: SIM_LINK_SEARCH_MAX_LENGTH,
135136
onChange: setSearch,
136137
onClearAll: () => setSearch(''),
137138
placeholder: SIM_LINKS_SEARCH_PLACEHOLDER,

‎apps/sim/app/sim/[[...path]]/page.tsx‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ import {
99
type SimLinkResolution,
1010
suggestSimLinks,
1111
} from '@/lib/sim-links/application/use-cases'
12-
import {
13-
parseTypedSimLink,
14-
SIM_LINK_SEARCH_MAX_LENGTH,
15-
simLinkNameSchema,
16-
} from '@/lib/sim-links/validation'
12+
import { parseTypedSimLink, simLinkNameSchema } from '@/lib/sim-links/validation'
1713
import { buildAuthCrossLink } from '@/app/(auth)/auth-redirect'
1814
import { LogoShell } from '@/app/(landing)/components/logo-shell'
1915
import { serializeSimLinkView } from '@/app/o/[organizationId]/links/search-params'
@@ -108,7 +104,7 @@ export default async function SimLinkPage({ params, searchParams }: SimLinkPageP
108104
const validName = simLinkNameSchema.safeParse(name).success
109105
// A name can't hold a space, so `sim card prices` is someone looking for a link, not naming one.
110106
if (result.kind === 'not_found' && /\s/.test(name)) {
111-
redirect(serializeSimLinkView(library, { search: name.slice(0, SIM_LINK_SEARCH_MAX_LENGTH) }))
107+
redirect(serializeSimLinkView(library, { search: name }))
112108
}
113109
const creatable = result.kind === 'not_found' && validName
114110
const similar = creatable

0 commit comments

Comments
 (0)