Unverified Commit 78b73f03 authored by Martin Joakim Ulstein's avatar Martin Joakim Ulstein Committed by GitHub

replace all 'athName' with 'athname' for consistency (#70690)

### What?
Consistently casing of pathname throughout the code-base. It is a simple
search and replace of all the ocuences 'athName' to 'athname'.

### Why?
I believe that the usage of the casing [pP]athName is likely a mistake,
as it is usually typed [pP]athname in the rest of the repo.
I think a case sensitive search replace from 'athName' to 'athname'
would be a small thing, and prevent this from growing.

### How?
I searched for pathname in the repo, and found a huge amount of hits.
Searching for 'athName' only returned a few.
The usePathname hook was the reason I came across this inconsistency. We
had the inconsistency in our own Next.js project, ie. `const pathName =
usePathname()`, and I noticed that when searching inside my project with
cases-sensitivity I found two hits of 'pathName' inside the
documentation for LoadableManifest.
This lead me to fork the repo and search, and then I found a few more
cases.
In each file I did a search for conflicts: if for example pathname was
already defined, it would be considered breaking if I changed a pathName
to pathname.
I could not find any cases where the variable was defined twice with the
same casing, so I believe this PR is safe.
I guess the test coverage/pipeline will tell us if this change is
breaking? If not I don't think I would be able to contribute that much
further in the time of writing.
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 47030ae2
......@@ -5,10 +5,10 @@ import Link from "next/link";
import { i18n, type Locale } from "../../../i18n-config";
export default function LocaleSwitcher() {
const pathName = usePathname();
const redirectedPathName = (locale: Locale) => {
if (!pathName) return "/";
const segments = pathName.split("/");
const pathname = usePathname();
const redirectedPathname = (locale: Locale) => {
if (!pathname) return "/";
const segments = pathname.split("/");
segments[1] = locale;
return segments.join("/");
};
......@@ -20,7 +20,7 @@ export default function LocaleSwitcher() {
{i18n.locales.map((locale) => {
return (
<li key={locale}>
<Link href={redirectedPathName(locale)}>{locale}</Link>
<Link href={redirectedPathname(locale)}>{locale}</Link>
</li>
);
})}
......
......@@ -8,13 +8,13 @@ export async function middleware(request: NextRequest) {
const basicAuth = `${process.env.WP_USER}:${process.env.WP_APP_PASS}`;
const pathNameWithoutTrailingSlash = request.nextUrl.pathname.replace(
const pathnameWithoutTrailingSlash = request.nextUrl.pathname.replace(
/\/$/,
"",
);
const response = await fetch(
`${process.env.NEXT_PUBLIC_WORDPRESS_API_URL}/wp-json/redirection/v1/redirect/?filterBy%5Burl-match%5D=plain&filterBy%5Burl%5D=${pathNameWithoutTrailingSlash}`,
`${process.env.NEXT_PUBLIC_WORDPRESS_API_URL}/wp-json/redirection/v1/redirect/?filterBy%5Burl-match%5D=plain&filterBy%5Burl%5D=${pathnameWithoutTrailingSlash}`,
{
headers: {
Authorization: `Basic ${Buffer.from(basicAuth).toString("base64")}`,
......@@ -27,7 +27,7 @@ export async function middleware(request: NextRequest) {
if (data?.items?.length > 0) {
const redirect = data.items.find(
(item: any) => item.url === pathNameWithoutTrailingSlash,
(item: any) => item.url === pathnameWithoutTrailingSlash,
);
if (!redirect) {
......
......@@ -7,15 +7,15 @@ import { SuperTokensConfig } from "supertokens-auth-react/lib/build/types";
import { ThirdPartyPreBuiltUI } from "supertokens-auth-react/recipe/thirdparty/prebuiltui";
import { EmailPasswordPreBuiltUI } from "supertokens-auth-react/recipe/emailpassword/prebuiltui";
const routerInfo: { router?: ReturnType<typeof useRouter>; pathName?: string } =
const routerInfo: { router?: ReturnType<typeof useRouter>; pathname?: string } =
{};
export function setRouter(
router: ReturnType<typeof useRouter>,
pathName: string,
pathname: string,
) {
routerInfo.router = router;
routerInfo.pathName = pathName;
routerInfo.pathname = pathname;
}
export const frontendConfig = (): SuperTokensConfig => {
......@@ -39,7 +39,7 @@ export const frontendConfig = (): SuperTokensConfig => {
...orig,
location: {
...orig.location,
getPathName: () => routerInfo.pathName!,
getPathname: () => routerInfo.pathname!,
assign: (url) => routerInfo.router!.push(url.toString()),
setHref: (url) => routerInfo.router!.push(url.toString()),
},
......
......@@ -42,8 +42,8 @@ export type ReactLoadableManifest = { [moduleId: string]: ManifestItem }
/**
* A manifest entry type for the react-loadable-manifest.json.
*
* The whole manifest.json is a type of `Record<pathName, LoadableManifest>`
* where pathName is a string-based key points to the path of the page contains
* The whole manifest.json is a type of `Record<pathname, LoadableManifest>`
* where pathname is a string-based key points to the path of the page contains
* each dynamic imports.
*/
export interface LoadableManifest {
......
'use client'
export { ReadPathName as default } from '../../components/read-path-name'
export { ReadPathname as default } from '../../components/read-path-name'
'use client'
export { ReadPathName as default } from '../../components/read-path-name'
export { ReadPathname as default } from '../../components/read-path-name'
import { usePathname } from 'next/navigation'
export function ReadPathName() {
export function ReadPathname() {
const pathname = usePathname()
return (
<div id="pathname" data-pathname={pathname}>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment