mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 04:15:30 +00:00
Fix version upgrade toast refresh issue (#179)
This commit is contained in:
parent
d20412301d
commit
27dde3a902
7 changed files with 54 additions and 6 deletions
|
|
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed issue with version upgrade toast not appearing without a hard refresh. ([#179](https://github.com/sourcebot-dev/sourcebot/pull/179))
|
||||
|
||||
## [2.8.0] - 2025-01-17
|
||||
|
||||
### Added
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
'use client';
|
||||
|
||||
import { NEXT_PUBLIC_DOMAIN_SUB_PATH } from "@/lib/environment.client";
|
||||
import { fileSourceResponseSchema, listRepositoriesResponseSchema, searchResponseSchema } from "@/lib/schemas";
|
||||
import { FileSourceRequest, FileSourceResponse, ListRepositoriesResponse, SearchRequest, SearchResponse } from "@/lib/types";
|
||||
import { fileSourceResponseSchema, getVersionResponseSchema, listRepositoriesResponseSchema, searchResponseSchema } from "@/lib/schemas";
|
||||
import { FileSourceRequest, FileSourceResponse, GetVersionResponse, ListRepositoriesResponse, SearchRequest, SearchResponse } from "@/lib/types";
|
||||
import assert from "assert";
|
||||
|
||||
export const search = async (body: SearchRequest): Promise<SearchResponse> => {
|
||||
|
|
@ -43,6 +43,17 @@ export const getRepos = async (): Promise<ListRepositoriesResponse> => {
|
|||
return listRepositoriesResponseSchema.parse(result);
|
||||
}
|
||||
|
||||
export const getVersion = async (): Promise<GetVersionResponse> => {
|
||||
const path = resolveServerPath("/api/version");
|
||||
const result = await fetch(path, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}).then(response => response.json());
|
||||
return getVersionResponseSchema.parse(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a subpath to a api route on the server (e.g., /api/search),
|
||||
* returns the full path to that route on the server, taking into account
|
||||
|
|
|
|||
15
packages/web/src/app/api/(server)/version/route.ts
Normal file
15
packages/web/src/app/api/(server)/version/route.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { SOURCEBOT_VERSION } from "@/lib/environment";
|
||||
import { GetVersionResponse } from "@/lib/types";
|
||||
|
||||
// Note: In Next.JS 14, GET methods with no params are cached by default at build time.
|
||||
// This creates issues since environment variables (like SOURCEBOT_VERSION) are
|
||||
// not available until runtime. To work around this, we fore the route to be
|
||||
// dynamic and evaluate on each request.
|
||||
// @see: https://nextjs.org/docs/14/app/building-your-application/routing/route-handlers#caching
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export const GET = async () => {
|
||||
return Response.json({
|
||||
version: SOURCEBOT_VERSION,
|
||||
} satisfies GetVersionResponse);
|
||||
}
|
||||
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
import { useToast } from "@/components/hooks/use-toast";
|
||||
import { ToastAction } from "@/components/ui/toast";
|
||||
import { NEXT_PUBLIC_SOURCEBOT_VERSION } from "@/lib/environment.client";
|
||||
import { useEffect } from "react";
|
||||
import { useLocalStorage } from "usehooks-ts";
|
||||
import { getVersion } from "../api/(client)/client";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
const GITHUB_TAGS_URL = "https://api.github.com/repos/sourcebot-dev/sourcebot/tags";
|
||||
const SEMVER_REGEX = /^v(\d+)\.(\d+)\.(\d+)$/;
|
||||
|
|
@ -23,8 +24,18 @@ export const UpgradeToast = () => {
|
|||
new Date(0).toUTCString()
|
||||
);
|
||||
|
||||
const { data: versionString } = useQuery({
|
||||
queryKey: ["version"],
|
||||
queryFn: () => getVersion(),
|
||||
select: (data) => data.version,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
const currentVersion = getVersionFromString(NEXT_PUBLIC_SOURCEBOT_VERSION);
|
||||
if (!versionString) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentVersion = getVersionFromString(versionString);
|
||||
if (!currentVersion) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -71,7 +82,7 @@ export const UpgradeToast = () => {
|
|||
|
||||
setUpgradeToastLastShownDate(new Date().toUTCString());
|
||||
});
|
||||
}, [setUpgradeToastLastShownDate, toast, upgradeToastLastShownDate]);
|
||||
}, [setUpgradeToastLastShownDate, toast, upgradeToastLastShownDate, versionString]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@ import { getEnv, getEnvNumber } from "./utils";
|
|||
export const ZOEKT_WEBSERVER_URL = getEnv(process.env.ZOEKT_WEBSERVER_URL, "http://localhost:6070")!;
|
||||
export const SHARD_MAX_MATCH_COUNT = getEnvNumber(process.env.SHARD_MAX_MATCH_COUNT, 10000);
|
||||
export const TOTAL_MAX_MATCH_COUNT = getEnvNumber(process.env.TOTAL_MAX_MATCH_COUNT, 100000);
|
||||
export const SOURCEBOT_VERSION = getEnv(process.env.SOURCEBOT_VERSION, 'unknown')!;
|
||||
export const NODE_ENV = process.env.NODE_ENV;
|
||||
|
|
|
|||
|
|
@ -153,3 +153,7 @@ export const listRepositoriesResponseSchema = z.object({
|
|||
Stats: repoStatsSchema,
|
||||
})
|
||||
});
|
||||
|
||||
export const getVersionResponseSchema = z.object({
|
||||
version: z.string(),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { z } from "zod";
|
||||
import { fileSourceRequestSchema, fileSourceResponseSchema, listRepositoriesResponseSchema, locationSchema, rangeSchema, repositorySchema, searchRequestSchema, searchResponseSchema, symbolSchema } from "./schemas";
|
||||
import { fileSourceRequestSchema, fileSourceResponseSchema, getVersionResponseSchema, listRepositoriesResponseSchema, locationSchema, rangeSchema, repositorySchema, searchRequestSchema, searchResponseSchema, symbolSchema } from "./schemas";
|
||||
|
||||
export type KeymapType = "default" | "vim";
|
||||
|
||||
|
|
@ -20,6 +20,8 @@ export type Repository = z.infer<typeof repositorySchema>;
|
|||
|
||||
export type Symbol = z.infer<typeof symbolSchema>;
|
||||
|
||||
export type GetVersionResponse = z.infer<typeof getVersionResponseSchema>;
|
||||
|
||||
export enum SearchQueryParams {
|
||||
query = "query",
|
||||
maxMatchDisplayCount = "maxMatchDisplayCount",
|
||||
|
|
|
|||
Loading…
Reference in a new issue