Skip to content

Commit

Permalink
Merge pull request #2081 from cprussin/upgrade-next-and-react
Browse files Browse the repository at this point in the history
chore: upgrade nextjs & react for all webapps
  • Loading branch information
cprussin authored Oct 31, 2024
2 parents 99acefa + d1a13fe commit bcf162f
Show file tree
Hide file tree
Showing 21 changed files with 2,285 additions and 2,360 deletions.
2 changes: 1 addition & 1 deletion apps/api-reference/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
20 changes: 10 additions & 10 deletions apps/api-reference/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@amplitude/analytics-browser": "^2.9.0",
"@amplitude/plugin-autocapture-browser": "^0.9.0",
"@floating-ui/react": "^0.26.17",
"@headlessui/react": "^2.0.4",
"@headlessui/react": "^2.2.0",
"@heroicons/react": "^2.1.4",
"@next/third-parties": "^14.2.4",
"@pythnetwork/client": "^2.22.0",
Expand All @@ -33,11 +33,11 @@
"connectkit": "^1.8.2",
"cryptocurrency-icons": "^0.18.1",
"framer-motion": "^11.3.8",
"next": "^14.2.4",
"next": "catalog:",
"next-themes": "^0.3.0",
"pino": "^9.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react": "catalog:",
"react-dom": "catalog:",
"react-markdown": "^9.0.1",
"shiki": "^1.7.0",
"viem": "^2.21.32",
Expand All @@ -46,16 +46,16 @@
},
"devDependencies": {
"@axe-core/react": "^4.9.1",
"@cprussin/eslint-config": "^3.0.0",
"@cprussin/jest-config": "^1.4.1",
"@cprussin/prettier-config": "^2.1.1",
"@cprussin/tsconfig": "^3.0.1",
"@cprussin/eslint-config": "catalog:",
"@cprussin/jest-config": "catalog:",
"@cprussin/prettier-config": "catalog:",
"@cprussin/tsconfig": "catalog:",
"@svgr/webpack": "^8.1.0",
"@tailwindcss/forms": "^0.5.7",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.6",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react": "catalog:",
"@types/react-dom": "catalog:",
"autoprefixer": "^10.4.19",
"eslint": "^9.5.0",
"jest": "^29.7.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
"use client";

import { notFound } from "next/navigation";
import type { ComponentProps } from "react";
import { type ComponentProps, use } from "react";

import * as apis from "../../../../apis";
import { EvmApi } from "../../../../components/EvmApi";

type Props = {
params: {
params: Promise<{
chain: string;
method: string;
};
}>;
};

const Page = ({ params }: Props) => {
const Page = (props: Props) => {
const params = use(props.params);
const chain: (typeof apis)[keyof typeof apis] | undefined = isKeyOf(
params.chain,
apis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import {
type ReactNode,
type MutableRefObject,
type RefObject,
createContext,
useContext,
useState,
Expand All @@ -17,15 +17,15 @@ import type { SupportedLanguage } from "./supported-language";
import { getLogger } from "../../browser-logger";

const HighlighterContext = createContext<
undefined | MutableRefObject<undefined | Highlighter>
undefined | RefObject<undefined | Highlighter>
>(undefined);

export const HighlighterProvider = ({
children,
}: {
children: ReactNode | ReactNode[];
}) => {
const highlighterRef = useRef<undefined | Highlighter>();
const highlighterRef = useRef<undefined | Highlighter>(undefined);
return (
<HighlighterContext.Provider value={highlighterRef}>
{children}
Expand Down
7 changes: 2 additions & 5 deletions apps/api-reference/src/components/EvmApi/parameter-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,8 @@ const PriceFeedListOptions = ({ priceFeedList }: PriceFeedListOptionsProps) => {
</div>
) : (
<ComboboxOptions className="h-80 overflow-y-auto py-1" modal={false}>
{({ option }) => {
// The `option` parameter is typed as `unknown` and we have to
// cast to get it to be correctly typed, see
// https://github.com/tailwindlabs/headlessui/issues/3326
const { feedId, name, description } = option as PriceFeed;
{({ option }: { option: PriceFeed }) => {
const { feedId, name, description } = option;
return (
<ComboboxOption
key={feedId}
Expand Down
4 changes: 2 additions & 2 deletions apps/api-reference/src/components/Markdown/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ComponentProps, Fragment } from "react";
import { type ComponentProps } from "react";
import MarkdownComponent from "react-markdown";

import { MARKDOWN_COMPONENTS } from "../../markdown-components";
Expand All @@ -12,7 +12,7 @@ export const Markdown = ({ inline, ...props }: Props) =>
<MarkdownComponent
components={{
...MARKDOWN_COMPONENTS,
p: ({ children }) => <Fragment>{children}</Fragment>,
p: ({ children }) => <>{children}</>,
}}
{...props}
/>
Expand Down
3 changes: 3 additions & 0 deletions apps/api-reference/src/markdown-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const MARKDOWN_COMPONENTS = {
</Code>
);
} else {
// @ts-expect-error react-markdown doesn't officially support react 19
// yet; there's no issues here in practice but the types don't currently
// unify
return <pre {...props} />;
}
},
Expand Down
2 changes: 1 addition & 1 deletion apps/staking/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
25 changes: 13 additions & 12 deletions apps/staking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"pull:env": "[ $CI ] || VERCEL_ORG_ID=team_BKQrg3JJFLxZyTqpuYtIY0rj VERCEL_PROJECT_ID=prj_3TIYzlYYncZx7wRtfmzG2YUsNzKp vercel env pull",
"start:dev": "next dev --port 3001",
"start:prod": "next start --port 3001",
"test:format": "jest --selectProjects format",
"test:format": "prettier --check .",
"test:lint": "jest --selectProjects lint",
"test:types": "tsc",
"test:unit": "jest --selectProjects unit"
Expand All @@ -34,34 +34,35 @@
"@solana/wallet-adapter-react-ui": "^0.9.35",
"@solana/wallet-adapter-wallets": "0.19.10",
"@solana/web3.js": "1.92.3",
"@vercel/functions": "^1.5.0",
"bcp-47": "^2.1.0",
"clsx": "^2.1.1",
"dnum": "^2.13.1",
"framer-motion": "^11.3.8",
"framer-motion": "catalog:",
"ip-range-check": "^0.2.0",
"next": "^14.2.5",
"next": "catalog:",
"pino": "^9.3.2",
"proxycheck-ts": "^0.0.11",
"react": "^18.3.1",
"react": "catalog:",
"react-aria": "^3.34.3",
"react-aria-components": "^1.3.3",
"react-dom": "^18.3.1",
"recharts": "^2.12.7",
"react-dom": "catalog:",
"recharts": "^2.13.2",
"swr": "^2.2.5",
"zod": "^3.23.8"
},
"devDependencies": {
"@axe-core/react": "^4.9.1",
"@cprussin/eslint-config": "^3.0.0",
"@cprussin/jest-config": "^1.4.1",
"@cprussin/prettier-config": "^2.1.1",
"@cprussin/tsconfig": "^3.0.1",
"@cprussin/eslint-config": "catalog:",
"@cprussin/jest-config": "catalog:",
"@cprussin/prettier-config": "catalog:",
"@cprussin/tsconfig": "catalog:",
"@svgr/webpack": "^8.1.0",
"@tailwindcss/forms": "^0.5.7",
"@types/jest": "^29.5.12",
"@types/node": "^22.0.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react": "catalog:",
"@types/react-dom": "catalog:",
"autoprefixer": "^10.4.19",
"eslint": "^9.8.0",
"jest": "^29.7.0",
Expand Down
3 changes: 3 additions & 0 deletions apps/staking/src/components/ErrorMessage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ const UnknownError = ({ error }: { error: unknown }) => {
</div>
</Button>
<m.div
// @ts-expect-error the framer-motion types don't currently expose props
// like `className` correctly for some reason, even though this works
// correctly...
className="overflow-hidden pt-1 opacity-60"
initial={{ height: 0 }}
animate={{ height: detailsOpen ? "auto" : 0 }}
Expand Down
3 changes: 3 additions & 0 deletions apps/staking/src/components/Faq/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export const Faq = ({ title, questions, className, ...props }: Props) => {
</Button>
</dt>
<m.dt
// @ts-expect-error the framer-motion types don't currently
// expose props like `className` correctly for some reason, even
// though this works correctly...
className="-mt-1 flex max-w-prose flex-col gap-4 overflow-hidden font-light"
initial={{ height: openItem === i ? "auto" : 0 }}
animate={{ height: openItem === i ? "auto" : 0 }}
Expand Down
23 changes: 13 additions & 10 deletions apps/staking/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type Geo, geolocation, ipAddress } from "@vercel/functions";
import ipRangeCheck from "ip-range-check";
import { type NextRequest, NextResponse } from "next/server";
import ProxyCheck from "proxycheck-ts";
Expand All @@ -24,16 +25,18 @@ const proxyCheckClient = PROXYCHECK_API_KEY
: undefined;

export const middleware = async (request: NextRequest) => {
if (isIpAllowlisted(request)) {
const ip = ipAddress(request);
if (isIpAllowlisted(ip)) {
return isBlockedSegment(request)
? rewrite(request, "/not-found")
: undefined;
} else {
if (await isProxyBlocked(request)) {
const geo = geolocation(request);
if (await isProxyBlocked(ip)) {
return rewrite(request, VPN_BLOCKED_PATH);
} else if (isGovernanceOnlyRegion(request)) {
} else if (isGovernanceOnlyRegion(geo)) {
return rewrite(request, GOVERNANCE_ONLY_PATH);
} else if (isRegionBlocked(request)) {
} else if (isRegionBlocked(geo)) {
return rewrite(request, GEO_BLOCKED_PATH);
} else if (isBlockedSegment(request)) {
return rewrite(request, "/not-found");
Expand All @@ -46,19 +49,19 @@ export const middleware = async (request: NextRequest) => {
const rewrite = (request: NextRequest, path: string) =>
NextResponse.rewrite(new URL(path, request.url));

const isIpAllowlisted = ({ ip }: NextRequest) =>
const isIpAllowlisted = (ip: string | undefined) =>
ip !== undefined &&
IP_ALLOWLIST.some((allowedRange) => ipRangeCheck(ip, allowedRange));

const isGovernanceOnlyRegion = ({ geo }: NextRequest) =>
geo?.country !== undefined &&
const isGovernanceOnlyRegion = (geo: Geo) =>
geo.country !== undefined &&
GOVERNANCE_ONLY_REGIONS.includes(geo.country.toLowerCase());

const isRegionBlocked = ({ geo }: NextRequest) =>
geo?.country !== undefined &&
const isRegionBlocked = (geo: Geo) =>
geo.country !== undefined &&
BLOCKED_REGIONS.includes(geo.country.toLowerCase());

const isProxyBlocked = async ({ ip }: NextRequest) => {
const isProxyBlocked = async (ip: string | undefined) => {
if (proxyCheckClient === undefined || ip === undefined) {
return false;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type PriceRawConfig = {
}

export const usePyth = (): PythHookData => {
const connectionRef = useRef<Connection>()
const connectionRef = useRef<Connection | undefined>(undefined)
const { cluster } = useContext(ClusterContext)
const [isLoading, setIsLoading] = useState(true)
const [rawConfig, setRawConfig] = useState<RawConfig>({ mappingAccounts: [] })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
12 changes: 6 additions & 6 deletions governance/xc_admin/packages/xc_admin_frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"dependencies": {
"@coral-xyz/anchor": "^0.29.0",
"@headlessui/react": "^1.7.7",
"@headlessui/react": "^2.2.0",
"@pythnetwork/client": "^2.22.0",
"@pythnetwork/solana-utils": "workspace:^",
"@pythnetwork/xc-admin-common": "workspace:*",
Expand All @@ -32,10 +32,10 @@
"copy-to-clipboard": "^3.3.3",
"gsap": "^3.11.4",
"message_buffer": "workspace:^",
"next": "^14.2.3",
"next": "catalog:",
"next-seo": "^5.15.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react": "catalog:",
"react-dom": "catalog:",
"react-hot-toast": "^2.4.0",
"sharp": "^0.33.4",
"use-debounce": "^9.0.2",
Expand All @@ -46,8 +46,8 @@
"devDependencies": {
"@svgr/webpack": "^6.3.1",
"@types/node": "^18.11.18",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react": "catalog:",
"@types/react-dom": "catalog:",
"@typescript-eslint/eslint-plugin": "^7.7.0",
"autoprefixer": "^10.4.8",
"eslint": "8.56.0",
Expand Down
6 changes: 1 addition & 5 deletions governance/xc_admin/packages/xc_admin_frontend/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
"cache": false
},
"start:dev": {
"dependsOn": [
"pull:env",
"@pythnetwork/hermes-client#build",
"@pythnetwork/solana-utils#build"
],
"dependsOn": ["pull:env", "^build"],
"persistent": true,
"cache": false
},
Expand Down
11 changes: 6 additions & 5 deletions packages/component-library/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { sans } from "@pythnetwork/fonts";
import { withThemeByClassName } from "@storybook/addon-themes";
import type { Preview, Decorator } from "@storybook/react";
import { useEffect } from "react";
import { useEffect, type ComponentType } from "react";

import "./tailwind.css";

Expand All @@ -14,9 +14,8 @@ const preview = {

export default preview;

const withRootClasses =
(...classes: string[]): Decorator =>
(storyFn) => {
const withRootClasses = (...classes: string[]): Decorator => {
const WithRootClasses = (Story: ComponentType) => {
useEffect(() => {
const root = document.querySelector("html");
const classList = classes
Expand All @@ -31,8 +30,10 @@ const withRootClasses =
return;
}
}, []);
return storyFn();
return <Story />;
};
return WithRootClasses;
};

export const decorators: Decorator[] = [
withRootClasses("font-sans antialiased", sans.variable),
Expand Down
Loading

0 comments on commit bcf162f

Please sign in to comment.