### What? Prevents "not found" error when trashing search-enabled documents in localized site. ### Why? **See issue https://github.com/payloadcms/payload/issues/13835 for details and reproduction of bug.** When a document is soft-deleted (has `deletedAt` timestamp), the search plugin's `afterChange` hook tries to sync the document but fails because `payload.findByID()` excludes trashed documents by default. **Original buggy code** in `packages/plugin-search/src/utilities/syncDocAsSearchIndex.ts` at lines 46-51: ```typescript docToSyncWith = await payload.findByID({ id, collection, locale: syncLocale, req, // MISSING: trash parameter! }) ``` ### How? Added detection for trashed documents and include `trash: true` parameter: ```typescript // Check if document is trashed (has deletedAt field) const isTrashDocument = doc && 'deletedAt' in doc && doc.deletedAt docToSyncWith = await payload.findByID({ id, collection, locale: syncLocale, req, // Include trashed documents when the document being synced is trashed trash: isTrashDocument, }) ``` ### Test Coverage Added - **Enabled trash functionality** in Posts collection for plugin-search tests - **Added comprehensive e2e test case** in `test/plugin-search/int.spec.ts` that verifies: 1. Creates a published post and verifies search document creation 2. Soft deletes the post (moves to trash) 3. Verifies search document is properly synced after trash operation 4. Cleans up by permanently deleting the trashed document --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Patrik Kozak <35232443+PatrikKozak@users.noreply.github.com>
37 lines
577 B
TypeScript
37 lines
577 B
TypeScript
import type { CollectionConfig } from 'payload'
|
|
|
|
import { postsSlug } from '../shared.js'
|
|
|
|
export const Posts: CollectionConfig = {
|
|
slug: postsSlug,
|
|
labels: {
|
|
singular: 'Post',
|
|
plural: 'Posts',
|
|
},
|
|
admin: {
|
|
useAsTitle: 'title',
|
|
},
|
|
trash: true,
|
|
versions: {
|
|
drafts: true,
|
|
},
|
|
fields: [
|
|
{
|
|
name: 'title',
|
|
label: 'Title',
|
|
type: 'text',
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'excerpt',
|
|
label: 'Excerpt',
|
|
type: 'text',
|
|
},
|
|
{
|
|
type: 'text',
|
|
name: 'slug',
|
|
localized: true,
|
|
},
|
|
],
|
|
}
|