Skip to content

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

fix: use slug instead of id in link

Greg Richardson92340ee81204
diff --git a/apps/docs/components/reference/OldVersionAlert.tsx b/apps/docs/components/reference/OldVersionAlert.tsx
index 1330b368232..55b94576d75 100644
--- a/apps/docs/components/reference/OldVersionAlert.tsx
+++ b/apps/docs/components/reference/OldVersionAlert.tsx
@@ -2,13 +2,24 @@ import Link from 'next/link'
import { useRouter } from 'next/router'
import { useMenuActiveRefId } from '~/hooks/useMenuState'
import Admonition from '../Admonition'
+import { ICommonSection } from './Reference.types'
-const OldVersionAlert = () => {
+export interface OldVersionAlertProps {
+ sections: ICommonSection[]
+}
+
+const OldVersionAlert = ({ sections }: OldVersionAlertProps) => {
const router = useRouter()
const activeRefId = useMenuActiveRefId()
+ const activeSection = sections.find(({ id }) => id === activeRefId)
+
// Remove the version number from URL to get the latest
- const latestVersionUrl = router.asPath.split('/').slice(0, -2).concat([activeRefId]).join('/')
+ const latestVersionUrl = router.asPath
+ .split('/')
+ .slice(0, -2)
+ .concat(activeSection ? [activeSection.slug] : [])
+ .join('/')
return (
<div className="sticky top-10 z-10 lg:top-14 lg:w-1/2">
diff --git a/apps/docs/components/reference/RefSectionHandler.tsx b/apps/docs/components/reference/RefSectionHandler.tsx
index 55f103a2c52..df5ed1c5700 100644
--- a/apps/docs/components/reference/RefSectionHandler.tsx
+++ b/apps/docs/components/reference/RefSectionHandler.tsx
@@ -23,7 +23,7 @@ interface RefSectionHandlerProps {
const RefSectionHandler = (props: RefSectionHandlerProps) => {
const router = useRouter()
- const slug = router.query.slug[0]
+ const [slug] = router.query.slug
// When user lands on a url like http://supabase.com/docs/reference/javascript/sign-up
// find the #sign-up element and scroll to that
@@ -32,7 +32,7 @@ const RefSectionHandler = (props: RefSectionHandlerProps) => {
}, [slug])
useEffect(() => {
- function handler(e: PopStateEvent) {
+ function handler() {
const [slug] = window.location.pathname.split('/').slice(-1)
document.getElementById(slug)?.scrollIntoView()
}
@@ -71,7 +71,7 @@ const RefSectionHandler = (props: RefSectionHandlerProps) => {
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</Head>
- {props.isOldVersion && <OldVersionAlert />}
+ {props.isOldVersion && <OldVersionAlert sections={props.sections} />}
<RefSubLayout>
{props.sections.map((section, i) => {
const sectionType = section.type
diff --git a/apps/docs/pages/reference/javascript/v1/[...slug].tsx b/apps/docs/pages/reference/javascript/v1/[...slug].tsx
index af3a890ab75..3fb14627bfe 100644
--- a/apps/docs/pages/reference/javascript/v1/[...slug].tsx
+++ b/apps/docs/pages/reference/javascript/v1/[...slug].tsx
@@ -1,4 +1,3 @@
-import { inspect } from 'util'
import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json'
import typeSpec from '~/../../spec/enrichments/tsdoc_v1/combined.json'
import spec from '~/../../spec/supabase_js_v1.yml' assert { type: 'yml' }