Compare commits

...
Author SHA1 Message Date
Peter Steinberger 56d83e00fc fix: make /search host-aware in SSR 2026-02-13 14:17:25 +01:00
Sash Zats 34583a640c fix: make /search mode-aware
Notes:\n- Medium: /search now depends on getSiteMode() during beforeLoad. On server-side routing, if VITE_SITE_MODE isn’t set and VITE_SOULHUB_SITE_URL is set (as in .env.local), getSiteMode() will resolve to souls and redirect /search to / even on the ClawdHub deployment. This is a regression risk vs the old always-/skills redirect. Confirm deployment envs guarantee correct mode. src/routes/search.tsx:9-31
2026-01-25 22:06:49 -05:00
3 changed files with 69 additions and 42 deletions
+44 -37
View File
@@ -7,25 +7,33 @@ vi.mock('@tanstack/react-router', () => ({
import { Route } from '../routes/search'
function runBeforeLoad(search: { q?: string; highlighted?: boolean }, hostname = 'clawdhub.com') {
const route = Route as unknown as {
__config: {
beforeLoad?: (args: {
search: { q?: string; highlighted?: boolean }
location: { url: URL }
}) => void
}
}
const beforeLoad = route.__config.beforeLoad as (args: {
search: { q?: string; highlighted?: boolean }
location: { url: URL }
}) => void
let thrown: unknown
try {
beforeLoad({ search, location: { url: new URL(`https://${hostname}/search`) } })
} catch (error) {
thrown = error
}
return thrown
}
describe('search route', () => {
it('redirects to the skills index', () => {
const route = Route as unknown as {
__config: {
beforeLoad?: (args: { search: { q?: string; highlighted?: boolean } }) => void
}
}
const beforeLoad = route.__config.beforeLoad as (args: {
search: { q?: string; highlighted?: boolean }
}) => void
let thrown: unknown
try {
beforeLoad({ search: { q: 'crab', highlighted: true } })
} catch (error) {
thrown = error
}
expect(thrown).toEqual({
it('redirects skills host to the skills index', () => {
expect(runBeforeLoad({ q: 'crab', highlighted: true }, 'clawdhub.com')).toEqual({
redirect: {
to: '/skills',
search: {
@@ -37,29 +45,28 @@ describe('search route', () => {
})
})
it('redirects to the skills index without query', () => {
const route = Route as unknown as {
__config: {
beforeLoad?: (args: { search: { q?: string; highlighted?: boolean } }) => void
}
}
const beforeLoad = route.__config.beforeLoad as (args: {
search: { q?: string; highlighted?: boolean }
}) => void
let thrown: unknown
try {
beforeLoad({ search: {} })
} catch (error) {
thrown = error
}
expect(thrown).toEqual({
it('redirects souls host with query to home search', () => {
expect(runBeforeLoad({ q: 'crab', highlighted: true }, 'onlycrabs.ai')).toEqual({
redirect: {
to: '/skills',
to: '/',
search: {
q: 'crab',
highlighted: undefined,
search: undefined,
},
replace: true,
},
})
})
it('redirects souls host without query to home with search mode', () => {
expect(runBeforeLoad({}, 'onlycrabs.ai')).toEqual({
redirect: {
to: '/',
search: {
q: undefined,
highlighted: undefined,
search: true,
},
replace: true,
},
+2 -2
View File
@@ -84,7 +84,7 @@ export default function Header() {
Upload
</Link>
{isSoulMode ? null : <Link to="/import">Import</Link>}
<Link to="/" search={{ q: undefined, highlighted: undefined, search: true }}>
<Link to="/search" search={{ q: undefined, highlighted: undefined }}>
Search
</Link>
{me ? <Link to="/stars">Stars</Link> : null}
@@ -138,7 +138,7 @@ export default function Header() {
</DropdownMenuItem>
)}
<DropdownMenuItem asChild>
<Link to="/" search={{ q: undefined, highlighted: undefined, search: true }}>
<Link to="/search" search={{ q: undefined, highlighted: undefined }}>
Search
</Link>
</DropdownMenuItem>
+23 -3
View File
@@ -1,16 +1,36 @@
import { createFileRoute, redirect } from '@tanstack/react-router'
import { detectSiteMode } from '../lib/site'
export const Route = createFileRoute('/search')({
validateSearch: (search) => ({
q: typeof search.q === 'string' && search.q.trim() ? search.q : undefined,
highlighted: search.highlighted === '1' || search.highlighted === 'true' ? true : undefined,
}),
beforeLoad: ({ search }) => {
beforeLoad: ({ search, location }) => {
const hostname =
(location as { url?: URL }).url?.hostname ??
(typeof window !== 'undefined' ? window.location.hostname : undefined)
const mode = detectSiteMode(hostname)
if (mode === 'skills') {
throw redirect({
to: '/skills',
search: {
q: search.q || undefined,
sort: undefined,
dir: undefined,
highlighted: search.highlighted || undefined,
view: undefined,
},
replace: true,
})
}
throw redirect({
to: '/skills',
to: '/',
search: {
q: search.q || undefined,
highlighted: search.highlighted || undefined,
highlighted: undefined,
search: search.q ? undefined : true,
},
replace: true,
})