Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade next and react to latest #549

Merged
merged 7 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
{
"ignoreRestSiblings": true
}
{ "ignoreRestSiblings": true }
],
"@typescript-eslint/no-empty-function": ["warn"],
"@typescript-eslint/no-empty-interface": [
"error",
{
"allowSingleExtends": false
}
{ "allowSingleExtends": false }
],
"@typescript-eslint/no-empty-object-type": ["warn"],
"curly": ["warn", "all"],
"@typescript-eslint/no-unused-expressions": [
"error", {
"allowTernary": true,
"enforceForJSX": true
}
"error",
{ "allowTernary": true, "enforceForJSX": true }
]
}
}
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm --silent dlx lint-staged
8 changes: 8 additions & 0 deletions .lintstagedrc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import path from 'path';

const buildEslintCommand = (filenames) =>
`next lint --fix --file ${filenames.map((f) => path.relative(process.cwd(), f)).join(' --file ')}`;

export default {
'*.{js,jsx,ts,tsx}': [buildEslintCommand, 'prettier --write'],
};
24 changes: 10 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"version": "0.0.1",
"engines": {
"node": "18.17.0"
"node": ">=v18.18.0"
},
"scripts": {
"preinstall": "npx only-allow pnpm",
Expand All @@ -21,7 +21,7 @@
"build-storybook": "storybook build",
"build-bibstem-index": "node ./scripts/gen-bibstem-index",
"lint": "next lint",
"prepare": "husky install"
"prepare": "husky"
},
"dependencies": {
"@chakra-ui/icons": "^2.1.0",
Expand Down Expand Up @@ -67,8 +67,6 @@
"dotenv": "^16.3.1",
"downshift": "^6.1.7",
"escape-html": "^1.0.3",
"eslint": "8",
"eslint-config-next": "^15.0.0",
"file-saver": "^2.0.5",
"framer-motion": "^6.5.1",
"fuse.js": "^6.6.2",
Expand All @@ -81,7 +79,7 @@
"lucene": "^2.1.1",
"match-sorter": "^6.3.1",
"memoize-one": "^6.0.0",
"next": "14.2.10",
"next": "15.0.1",
"next-build-id": "^3.0.0",
"nprogress": "^0.2.0",
"pino": "^8.16.2",
Expand All @@ -90,7 +88,7 @@
"qs": "^6.11.0",
"ramda": "^0.28.0",
"ramda-adjunct": "^3.3.0",
"react": "^18.2.0",
"react": "^18.3.1",
"react-compound-slider": "^3.4.0",
"react-device-detect": "^2.2.3",
"react-error-boundary": "^4.0.4",
Expand Down Expand Up @@ -153,14 +151,16 @@
"@vitest/coverage-v8": "^0.34.5",
"@vitest/ui": "^0.29.2",
"c8": "^7.13.0",
"husky": "^8.0.0",
"eslint": "^9.13.0",
"eslint-config-next": "^15.0.1",
"husky": "^9.1.6",
"identity-obj-proxy": "^3.0.0",
"iron-session": "^6.3.1",
"lint-staged": "^11.2.6",
"msw": "^1.2.3",
"msw-storybook-addon": "^1.8.0",
"prettier": "^2.3.0",
"react-dom": "^18.2.0",
"react-dom": "^18.3.1",
"react-is": "^17.0.2",
"regenerator-runtime": "^0.13.9",
"storybook": "^7.5.3",
Expand All @@ -173,12 +173,8 @@
"webpack": "^5.94.0"
},
"volta": {
"node": "18.17.0"
},
"lint-staged": {
"**/*.ts(x)?": [
"prettier --write"
]
"node": "18.18.0",
"yarn": "1.22.19"
},
"msw": {
"workerDirectory": "public"
Expand Down
3,505 changes: 1,842 additions & 1,663 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ import { Favicons } from '@/components/Favicons/Favicons';
import { BRAND_NAME_FULL } from '@/config';
import { LandingTabsStatic } from '@/components/LandingTabs';

const LandingTabs = dynamic(() => import('@/components/LandingTabs/LandingTabs').then((mod) => mod.LandingTabs), {
ssr: false,
loading: () => <LandingTabsStatic />,
});
const LandingTabs = dynamic(
() =>
import('@/components/LandingTabs/LandingTabs').then((mod) => ({
default: mod.LandingTabs,
})),
{
ssr: false,
loading: () => <LandingTabsStatic />,
},
);

const LANDING_PAGES = ['/', '/classic-form', '/paper-form'];
export const Layout: FC = ({ children }) => {
Expand Down
13 changes: 11 additions & 2 deletions src/components/NavBar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ import { FC } from 'react';
import { SimpleLink } from '@/components/SimpleLink';

const AppModeDropdown = dynamic<Record<string, never>>(
() => import('./AppModeDropdown').then((mod) => mod.AppModeDropdown),
() =>
import('./AppModeDropdown').then((mod) => ({
default: mod.AppModeDropdown,
})),
{
ssr: false,
},
);

const NavMenus = dynamic<Record<string, never>>(() => import('./NavMenus').then((mod) => mod.NavMenus), { ssr: false });
const NavMenus = dynamic<Record<string, never>>(
() =>
import('./NavMenus').then((mod) => ({
default: mod.NavMenus,
})),
{ ssr: false },
);

export const NavBar: FC = () => {
return (
Expand Down
5 changes: 4 additions & 1 deletion src/components/ResultList/Item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import { getFormattedNumericPubdate, unwrapStringValue } from '@/utils/common/fo
import { IDocsEntity } from '@/api/search/types';

const AbstractPreview = dynamic<IAbstractPreviewProps>(
() => import('./AbstractPreview').then((mod) => mod.AbstractPreview),
() =>
import('./AbstractPreview').then((mod) => ({
default: mod.AbstractPreview,
})),
{ ssr: false },
);
export interface IItemProps {
Expand Down
26 changes: 22 additions & 4 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ const emitAnalytics = async (req: NextRequest): Promise<void> => {

// For abs/ routes we want to send emit an event to the link gateway
if (path.startsWith('/abs')) {
const url = `${process.env.BASE_URL}/link_gateway${path.replace('/abs', '')}`;
const url = `${process.env.BASE_URL}/link_gateway${path.replace(
'/abs',
'',
)}`;
log.debug({ path, url }, 'Emitting abs route event to link gateway');

try {
Expand All @@ -126,6 +129,15 @@ const emitAnalytics = async (req: NextRequest): Promise<void> => {
return Promise.resolve();
};

const getIp = (req: NextRequest) =>
(
req.headers.get('X-Original-Forwarded-For') ||
req.headers.get('X-Forwarded-For') ||
req.headers.get('X-Real-Ip')
)
.split(',')
.shift() || 'unknown';

export async function middleware(req: NextRequest) {
const path = req.nextUrl.pathname;
log.info(
Expand All @@ -147,7 +159,7 @@ export async function middleware(req: NextRequest) {
return res;
}

const ip = req.ip || req.headers.get('x-forwarded-for') || 'unknown';
const ip = getIp(req);

// Apply rate limiting
if (!rateLimit(ip)) {
Expand All @@ -171,15 +183,21 @@ export async function middleware(req: NextRequest) {
return loginMiddleware(req, res);
}

if (path.startsWith('/user/account/register') || path.startsWith('/user/forgotpassword')) {
if (
path.startsWith('/user/account/register') ||
path.startsWith('/user/forgotpassword')
) {
return redirectIfAuthenticated(req, res);
}

if (path.startsWith('/user/libraries') || path.startsWith('/user/settings')) {
return protectedRoute(req, res);
}

if (path.startsWith('/user/account/verify/change-email') || path.startsWith('/user/account/verify/register')) {
if (
path.startsWith('/user/account/verify/change-email') ||
path.startsWith('/user/account/verify/register')
) {
return verifyMiddleware(req, res);
}

Expand Down
11 changes: 7 additions & 4 deletions src/middlewares/botCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ enum CRAWLER_RESULT {
}

const getIp = (req: NextRequest) =>
req.headers.get('X-Original-Forwarded-For') ||
req.headers.get('X-Forwarded-For') ||
req.headers.get('X-Real-Ip') ||
req.ip;
(
req.headers.get('X-Original-Forwarded-For') ||
req.headers.get('X-Forwarded-For') ||
req.headers.get('X-Real-Ip')
)
.split(',')
.shift() || 'unknown';

const crawlerCheck = async (req: NextRequest, ip: string, ua: string) => {
try {
Expand Down
5 changes: 4 additions & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ if (process.env.NEXT_PUBLIC_API_MOCKING === 'enabled' && process.env.NODE_ENV !=
}

const TopProgressBar = dynamic<Record<string, never>>(
() => import('@/components/TopProgressBar').then((mod) => mod.TopProgressBar),
() =>
import('@/components/TopProgressBar').then((mod) => ({
default: mod.TopProgressBar,
})),
{
ssr: false,
},
Expand Down
5 changes: 4 additions & 1 deletion src/pages/abs/[id]/abstract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ import { IADSApiSearchParams, IDocsEntity } from '@/api/search/types';
import { getAbstractParams } from '@/api/search/models';

const AllAuthorsModal = dynamic<IAllAuthorsModalProps>(
() => import('@/components/AllAuthorsModal').then((m) => m.AllAuthorsModal),
() =>
import('@/components/AllAuthorsModal').then((m) => ({
default: m.AllAuthorsModal,
})),
{ ssr: false },
);

Expand Down
27 changes: 18 additions & 9 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,26 @@ import { makeSearchParams, normalizeSolrSort } from '@/utils/common/search';
import { SolrSort } from '@/api/models';

const SearchExamples = dynamic<ISearchExamplesProps>(
() => import('@/components/SearchExamples').then((m) => m.SearchExamples),
() =>
import('@/components/SearchExamples').then((m) => ({
default: m.SearchExamples,
})),
{ ssr: false, loading: () => <SearchExamplesPlaceholder /> },
);
const Pager = dynamic<IPagerProps>(() => import('@/components/Pager').then((m) => m.Pager), {
ssr: false,
loading: () => (
<Center>
<Spinner />
</Center>
),
});
const Pager = dynamic<IPagerProps>(
() =>
import('@/components/Pager').then((m) => ({
default: m.Pager,
})),
{
ssr: false,
loading: () => (
<Center>
<Spinner />
</Center>
),
},
);

const HomePage: NextPage = () => {
const { settings } = useSettings();
Expand Down
10 changes: 8 additions & 2 deletions src/pages/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,18 @@ import { defaultParams } from '@/api/search/models';
import { SolrSort } from '@/api/models';

const YearHistogramSlider = dynamic<IYearHistogramSliderProps>(
() => import('@/components/SearchFacet/YearHistogramSlider').then((mod) => mod.YearHistogramSlider),
() =>
import('@/components/SearchFacet/YearHistogramSlider').then((mod) => ({
default: mod.YearHistogramSlider,
})),
{ ssr: false },
);

const SearchFacets = dynamic<ISearchFacetsProps>(
() => import('@/components/SearchFacet').then((mod) => mod.SearchFacets),
() =>
import('@/components/SearchFacet').then((mod) => ({
default: mod.SearchFacets,
})),
{ ssr: false },
);

Expand Down
28 changes: 20 additions & 8 deletions src/pages/user/orcid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,26 @@ import dynamic from 'next/dynamic';
import Head from 'next/head';
import { BRAND_NAME_FULL } from '@/config';

const UserSettings = dynamic(() => import('@/components/Orcid/UserSettings').then((m) => m.UserSettings), {
ssr: false,
loading: () => <Spinner />,
});
const WorksTable = dynamic(() => import('@/components/Orcid/WorksTable').then((m) => m.WorksTable), {
ssr: false,
loading: () => <Spinner />,
});
const UserSettings = dynamic(
() =>
import('@/components/Orcid/UserSettings').then((m) => ({
default: m.UserSettings,
})),
{
ssr: false,
loading: () => <Spinner />,
},
);
const WorksTable = dynamic(
() =>
import('@/components/Orcid/WorksTable').then((m) => ({
default: m.WorksTable,
})),
{
ssr: false,
loading: () => <Spinner />,
},
);

const setOrcidModeSelector = (state: AppState) => state.setOrcidMode;
const orcidModeActiveSelector = (state: AppState) => state.orcid.active;
Expand Down
Loading