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

[BUG-1919] experimental app router updates to next 15 and react 19 #1994

Open
wants to merge 11 commits into
base: canary
Choose a base branch
from
Open
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
39 changes: 39 additions & 0 deletions .changeset/three-singers-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
'@faustwp/experimental-app-router': minor
---

---

## '@faustwp/experimental-app-router': minor

Update @faustwp/experimental-app-router to account for next 15 changes to cookies and update NextResponse import

Notable changes:

- Adding await to all cookies requests as per Next documentation: https://nextjs.org/docs/app/api-reference/functions/cookies

```
import { cookies } from 'next/headers'

export default async function Page() {
const cookieStore = await cookies()
const theme = cookieStore.get('theme')
return '...'
}
```

- Files changed:

- packages/experimental-app-router/src/server-actions/logoutAction.ts
- packages/experimental-app-router/src/server-actions/utils/setRefreshToken.ts
- packages/experimental-app-router/src/server/auth/fetchTokens.ts
- packages/experimental-app-router/src/server/routeHandler/tokenHandler.ts

- Updated Next App Router example to use latest next version and React 19 RC.
- Updated Example Login form using React 19s useActionState
- Updated Awaiting of params for Next 15
- Files Changed:
- examples/next/app-router/app/login/page.tsx
- examples/next/app-router/package.json
- examples/next/app-router/[slug]hasPreviewProps.ts (made async)
- examples/next/app-router/[slug]page.tsx
7 changes: 5 additions & 2 deletions examples/next/app-router/app/[slug]/hasPreviewProps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export function hasPreviewProps(props: any) {
return props?.searchParams?.preview === 'true' && !!props?.searchParams?.p;
export async function hasPreviewProps(props: any) {
const { searchParams } = await props;
const { preview, p } = await searchParams;

return preview === 'true' && !!p;
}
7 changes: 5 additions & 2 deletions examples/next/app-router/app/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { hasPreviewProps } from './hasPreviewProps';
import { PleaseLogin } from '@/components/please-login';

export default async function Page(props) {
const isPreview = hasPreviewProps(props);
const id = isPreview ? props.searchParams.p : props.params.slug;
const { searchParams, params } = await props;
const { slug } = await params;
const { p } = await searchParams;
const isPreview = await hasPreviewProps(props);
const id = isPreview ? p : slug;

let client = isPreview ? await getAuthClient() : await getClient();

Expand Down
17 changes: 5 additions & 12 deletions examples/next/app-router/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
'use client';

import { useFormState, useFormStatus } from 'react-dom';
import { loginAction } from './action';

function SubmitButton() {
const status = useFormStatus();
return (
<button disabled={status.pending}>
{status.pending ? 'Loading...' : 'Login'}
</button>
);
}
import { useActionState } from 'react';

export default function Page() {
const [state, formAction] = useFormState(loginAction, {});
const [state, formAction, isPending] = useActionState(loginAction, {});

return (
<>
Expand All @@ -30,7 +21,9 @@ export default function Page() {
<input type="password" name="password" />
</fieldset>

<SubmitButton />
<button disabled={isPending}>
{isPending ? 'Loading...' : 'Login'}
</button>

{state.error && (
<p dangerouslySetInnerHTML={{ __html: state.error }}></p>
Expand Down
2 changes: 1 addition & 1 deletion examples/next/app-router/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.
Loading