From 5bf24c29ef265216c03548d78a5a7e230d271138 Mon Sep 17 00:00:00 2001 From: Ahmed Abouzied Date: Mon, 6 Jan 2025 16:36:36 +0100 Subject: [PATCH 1/2] [DOC]: Fix anchors in links to docs.trychroma.com - Closes #3395 - Also removes the not used useContext react import. Signed-off-by: Ahmed Abouzied --- docs/docs.trychroma.com/context/app-context.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/docs.trychroma.com/context/app-context.tsx b/docs/docs.trychroma.com/context/app-context.tsx index af5b9b9be91..fbbba79d9f7 100644 --- a/docs/docs.trychroma.com/context/app-context.tsx +++ b/docs/docs.trychroma.com/context/app-context.tsx @@ -2,7 +2,6 @@ import React, { createContext, useState, ReactNode, - useContext, useEffect, } from "react"; import { usePathname, useRouter, useSearchParams } from "next/navigation"; @@ -26,12 +25,14 @@ export const AppContextProvider = ({ children }: { children: ReactNode }) => { ); const router = useRouter(); const pathname = usePathname(); + // Don't consider the hash if the user is going to a differnet path. + const anchor = (pathname == window.location.pathname) ? window.location.hash : ""; useEffect(() => { if (language === "typescript") { - router.replace(`${pathname}?lang=typescript`); + router.replace(pathname + "?lang=typescript" + anchor); } else { - router.replace(pathname); + router.replace(pathname + anchor); } }, [language]); From c0927dfa8860750e66d290209eaa5cf62e36306c Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Mon, 6 Jan 2025 19:55:34 +0200 Subject: [PATCH 2/2] fix: moveing the anchor handling under useeffect to prevent next.js window is not defined error --- docs/docs.trychroma.com/context/app-context.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/docs.trychroma.com/context/app-context.tsx b/docs/docs.trychroma.com/context/app-context.tsx index fbbba79d9f7..7bc47d38736 100644 --- a/docs/docs.trychroma.com/context/app-context.tsx +++ b/docs/docs.trychroma.com/context/app-context.tsx @@ -13,7 +13,7 @@ export interface AppContextValue { const AppContextDefaultValue: AppContextValue = { language: "python", - setLanguage: () => {}, + setLanguage: () => { }, }; const AppContext = createContext(AppContextDefaultValue); @@ -25,16 +25,17 @@ export const AppContextProvider = ({ children }: { children: ReactNode }) => { ); const router = useRouter(); const pathname = usePathname(); - // Don't consider the hash if the user is going to a differnet path. - const anchor = (pathname == window.location.pathname) ? window.location.hash : ""; useEffect(() => { + // Don't consider the hash if the user is going to a differnet path. + const anchor = (pathname === window.location.pathname) ? window.location.hash : ""; + if (language === "typescript") { router.replace(pathname + "?lang=typescript" + anchor); } else { router.replace(pathname + anchor); } - }, [language]); + }, [language, pathname]); return (