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

feat(next): pass through query params from document view to find operations #10343

Merged
merged 1 commit into from
Jan 6, 2025
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
1 change: 1 addition & 0 deletions packages/next/src/views/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const Account: React.FC<AdminViewProps> = async ({
collectionSlug: collectionConfig.slug,
locale,
payload,
req,
user,
})

Expand Down
1 change: 1 addition & 0 deletions packages/next/src/views/CreateFirstUser/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const CreateFirstUserView: React.FC<AdminViewProps> = async ({ initPageRe
collectionSlug: collectionConfig.slug,
locale,
payload: req.payload,
req,
user: req.user,
})

Expand Down
21 changes: 20 additions & 1 deletion packages/next/src/views/Document/getDocumentData.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { sanitizeID } from '@payloadcms/ui/shared'
import { type Locale, logError, type Payload, type TypedUser, type TypeWithID } from 'payload'
import {
type Locale,
logError,
type Payload,
type PayloadRequest,
type TypedUser,
type TypeWithID,
} from 'payload'

type Args = {
collectionSlug?: string
globalSlug?: string
id?: number | string
locale?: Locale
payload: Payload
req?: PayloadRequest
user?: TypedUser
}

Expand All @@ -16,6 +24,7 @@ export const getDocumentData = async ({
globalSlug,
locale,
payload,
req,
user,
}: Args): Promise<null | Record<string, unknown> | TypeWithID> => {
const id = sanitizeID(idArg)
Expand All @@ -31,6 +40,11 @@ export const getDocumentData = async ({
fallbackLocale: false,
locale: locale?.code,
overrideAccess: false,
req: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels odd to construct a new req object here instead of passing it through outright. I imagine this is to reduce the size of the actual request as much as possible. Pretty sure you wouldn't have to send user as a stand-alone property in this case.

Copy link
Member Author

@AlessioGr AlessioGr Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imagine this is to reduce the size of the actual request as much as possible

Doesn't matter since this all runs on the server anyways.

I mainly wanted to avoid the overhead of spreading req in order to remove/isolate the transactionID

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

query: req?.query,
search: req?.search,
searchParams: req?.searchParams,
},
user,
})
}
Expand All @@ -43,6 +57,11 @@ export const getDocumentData = async ({
fallbackLocale: false,
locale: locale?.code,
overrideAccess: false,
req: {
query: req?.query,
search: req?.search,
searchParams: req?.searchParams,
},
user,
})
}
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/views/Document/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const renderDocument = async ({
globalSlug,
locale,
payload,
req,
user,
}))

Expand Down
Loading