Skip to content

Commit

Permalink
replace all 'athName' with 'athname' for consistency (#70690)
Browse files Browse the repository at this point in the history
### 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: JJ Kasper <[email protected]>
  • Loading branch information
2 people authored and kdy1 committed Oct 10, 2024
1 parent f3e1e0e commit 2a44893
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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("/");
};
Expand All @@ -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>
);
})}
Expand Down
6 changes: 3 additions & 3 deletions examples/cms-wordpress/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")}`,
Expand All @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions examples/with-supertokens/app/config/frontend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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()),
},
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/server/load-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use client'

export { ReadPathName as default } from '../../components/read-path-name'
export { ReadPathname as default } from '../../components/read-path-name'
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app-basepath/app/use-pathname/page.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use client'

export { ReadPathName as default } from '../../components/read-path-name'
export { ReadPathname as default } from '../../components/read-path-name'
2 changes: 1 addition & 1 deletion test/e2e/app-dir/app-basepath/components/read-path-name.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { usePathname } from 'next/navigation'

export function ReadPathName() {
export function ReadPathname() {
const pathname = usePathname()
return (
<div id="pathname" data-pathname={pathname}>
Expand Down

0 comments on commit 2a44893

Please sign in to comment.