Skip to content

Commit

Permalink
fix: disappearing api playground button (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored Jun 4, 2024
1 parent 91275ed commit 4853127
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/fdr-sdk/src/navigation/utils/findNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function findNode(root: FernNavigation.RootNode, slug: string[]): Node {

const redirect = hasPointsTo(found.node) ? found.node.pointsTo : version?.pointsTo ?? root.pointsTo;

if (redirect == null || urljoin(redirect) === slugToFind) {
if (redirect == null || redirect === slugToFind) {
return { type: "notFound", redirect: undefined };
}

Expand Down
4 changes: 2 additions & 2 deletions packages/fdr-sdk/src/navigation/utils/traverseNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export function traverseNavigation(
const v = visit(node, index, parents);
if (v === SKIP) {
return;
} else if (v === STOP || v === CONTINUE) {
return v;
} else if (v === STOP) {
return STOP;
}
return visitDiscriminatedUnion(node)._visit({
root: (root) => internalTraverser(root.child, undefined, [...parents, root]),
Expand Down
29 changes: 14 additions & 15 deletions packages/ui/app/src/hooks/useViewportSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ export function useViewportSize(): { width: number; height: number } {
typeof window !== "undefined" ? window.innerHeight : 0,
);

useLayoutEffect(() => {
if (typeof window === "undefined") {
return;
}
if (typeof window !== "undefined") {
// eslint-disable-next-line react-hooks/rules-of-hooks
useLayoutEffect(() => {
const handleResize = () => {
setViewportHeight(window.innerHeight);
setViewportWidth(window.innerWidth);
};

const handleResize = () => {
setViewportHeight(window.innerHeight);
setViewportWidth(window.innerWidth);
};
handleResize();

handleResize();

window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
};
}, []);
window.addEventListener("resize", handleResize);
return () => {
window.removeEventListener("resize", handleResize);
};
}, []);
}

return { width, height };
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ApiDefinitionHolder } from "@fern-api/fdr-sdk/dist/navigation/ApiDefinitionHolder";
import { collectApiReferences } from "@fern-api/fdr-sdk/dist/navigation/utils/collectApiReferences";
import { convertLoadDocsForUrlResponse } from "@fern-api/fdr-sdk/dist/navigation/utils/convertLoadDocsForUrlResponse";
import { findNode } from "@fern-api/fdr-sdk/dist/navigation/utils/findNode";
import { ApiDefinitionResolver, ApiTypeResolver, REGISTRY_SERVICE, type ResolvedRootPackage } from "@fern-ui/ui";
import { NextApiHandler, NextApiResponse } from "next";
import { buildUrlFromApiNode } from "../../../utils/buildUrlFromApi";
Expand Down Expand Up @@ -36,17 +35,12 @@ const resolveApiHandler: NextApiHandler = async (
}

const docs = docsResponse.body;

const basePathSlug =
docs.baseUrl.basePath != null ? docs.baseUrl.basePath.split("/").filter((t) => t.length > 0) : [];
const root = convertLoadDocsForUrlResponse(docsResponse.body);
const found = findNode(root, basePathSlug);
const node = found.type === "found" ? found.currentVersion ?? found.currentTab ?? found.sidebar : root;

const featureFlags = await getFeatureFlags(docs.baseUrl.domain);

const packagesPromise: Promise<ResolvedRootPackage>[] = [];
collectApiReferences(node).forEach((apiReference) => {
collectApiReferences(root).forEach((apiReference) => {
const api = docs.definition.apis[apiReference.apiDefinitionId];
if (api == null) {
return;
Expand Down

0 comments on commit 4853127

Please sign in to comment.