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

Double create request #11384

Closed
Girbi opened this issue Feb 25, 2025 · 4 comments
Closed

Double create request #11384

Girbi opened this issue Feb 25, 2025 · 4 comments

Comments

@Girbi
Copy link

Girbi commented Feb 25, 2025

Describe the Bug

I get double GET request for a create, on pages and posts ( from the website template in V3 ).

Image

Image

Code for posts:
`import { admin } from '@/access/admin'
import { slugField } from '@/fields/slug'
import {
MetaDescriptionField,
MetaImageField,
MetaTitleField,
OverviewField,
PreviewField,
} from '@payloadcms/plugin-seo/fields'
import {
BlocksFeature,
HeadingFeature,
HorizontalRuleFeature,
lexicalEditor,
} from '@payloadcms/richtext-lexical'
import type { CollectionConfig } from 'payload'
import { Banner } from '../../blocks/Banner/config'
import { Code } from '../../blocks/Code/config'
import { MediaBlock } from '../../blocks/MediaBlock/config'
import { generatePreviewPath } from '../../utilities/generatePreviewPath'
import { populateAuthors } from './hooks/populateAuthors'
import { revalidateDelete, revalidatePost } from './hooks/revalidatePost'
import { editor, editorOrPublished } from '@/access/editor'

export const Posts: CollectionConfig<'posts'> = {
slug: 'posts',
access: {
create: admin,
delete: admin,
read: editor,
update: admin,
},
// This config controls what's populated by default when a post is referenced
// https://payloadcms.com/docs/queries/select#defaultpopulate-collection-config-property
// Type safe if the collection slug generic is passed to 'CollectionConfig - 'CollectionConfig<'posts'>
defaultPopulate: {
title: true,
slug: true,
categories: true,
meta: {
image: true,
description: true,
},
},
admin: {
defaultColumns: ['title', 'slug', 'updatedAt'],
livePreview: {
url: ({ data, req, locale }) => {
const path = generatePreviewPath({
slug: typeof data?.slug === 'string' ? data.slug : '',
collection: 'posts',
req,
locale: locale.code,
})

    return path
  },
},
preview: (data, { req, locale }) =>
  generatePreviewPath({
    slug: typeof data?.slug === 'string' ? data.slug : '',
    collection: 'posts',
    req,
    locale,
  }),
useAsTitle: 'title',

},
fields: [
{
name: 'title',
type: 'text',
required: true,
},
{
type: 'tabs',
tabs: [
{
fields: [
{
name: 'heroImage',
type: 'upload',
relationTo: 'media',
},
{
name: 'content',
type: 'richText',
editor: lexicalEditor({
features: ({ rootFeatures }) => {
return [
...rootFeatures,
HeadingFeature({ enabledHeadingSizes: ['h1', 'h2', 'h3', 'h4'] }),
BlocksFeature({ blocks: [Banner, Code, MediaBlock] }),
HorizontalRuleFeature(),
]
},
}),
label: false,
required: true,
},
],
label: 'Content',
},
{
fields: [
{
name: 'relatedPosts',
type: 'relationship',
admin: {
position: 'sidebar',
},
filterOptions: ({ id }) => {
return {
id: {
not_in: [id],
},
}
},
hasMany: true,
relationTo: 'posts',
},
{
name: 'categories',
type: 'relationship',
admin: {
position: 'sidebar',
},
hasMany: true,
relationTo: 'categories',
},
],
label: 'Meta',
},
{
name: 'meta',
label: 'SEO',
fields: [
OverviewField({
titlePath: 'meta.title',
descriptionPath: 'meta.description',
imagePath: 'meta.image',
}),
MetaTitleField({
hasGenerateFn: true,
}),
MetaImageField({
relationTo: 'media',
}),

        MetaDescriptionField({}),
        PreviewField({
          // if the 'generateUrl' function is configured
          hasGenerateFn: true,

          // field paths to match the target field for data
          titlePath: 'meta.title',
          descriptionPath: 'meta.description',
        }),
      ],
    },
  ],
},
{
  name: 'publishedAt',
  type: 'date',
  admin: {
    date: {
      pickerAppearance: 'dayAndTime',
    },
    position: 'sidebar',
  },
  hooks: {
    beforeChange: [
      ({ siblingData, value }) => {
        if (siblingData._status === 'published' && !value) {
          return new Date()
        }
        return value
      },
    ],
  },
},
{
  name: 'authors',
  type: 'relationship',
  admin: {
    position: 'sidebar',
  },
  hasMany: true,
  relationTo: 'users',
},
// This field is only used to populate the user data via the 'populateAuthors' hook
// This is because the 'user' collection has access control locked to protect user privacy
// GraphQL will also not return mutated user data that differs from the underlying schema
{
  name: 'populatedAuthors',
  type: 'array',
  access: {
    update: () => false,
  },
  admin: {
    disabled: true,
    readOnly: true,
  },
  fields: [
    {
      name: 'id',
      type: 'text',
    },
    {
      name: 'name',
      type: 'text',
    },
  ],
},
...slugField(),

],
hooks: {
afterChange: [revalidatePost],
afterRead: [populateAuthors],
afterDelete: [revalidateDelete],
},
versions: {
drafts: {
autosave: {
interval: 100, // We set this interval for optimal live preview
},
schedulePublish: true,
},
maxPerDoc: 50,
},
}
`

Link to the code that reproduces this issue

none

Reproduction Steps

Just running in dev mode, i am using postgres adapter.

Which area(s) are affected? (Select all that apply)

area: ui

Environment Info

Binaries:
  Node: 22.13.1
  npm: 11.1.0
  Yarn: 1.22.22
  pnpm: 10.4.1
Relevant Packages:
  payload: 3.24.0
  next: 15.1.7
  @payloadcms/db-postgres: 3.24.0
  @payloadcms/email-nodemailer: 3.24.0
  @payloadcms/graphql: 3.24.0
  @payloadcms/live-preview: 3.24.0
  @payloadcms/live-preview-react: 3.24.0
  @payloadcms/next/utilities: 3.24.0
  @payloadcms/plugin-form-builder: 3.24.0
  @payloadcms/plugin-nested-docs: 3.24.0
  @payloadcms/plugin-redirects: 3.24.0
  @payloadcms/plugin-search: 3.24.0
  @payloadcms/plugin-seo: 3.24.0
  @payloadcms/richtext-lexical: 3.24.0
  @payloadcms/translations: 3.24.0
  @payloadcms/ui/shared: 3.24.0
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024
  Available memory (MB): 15958
  Available CPU cores: 12
@Girbi Girbi added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Feb 25, 2025
Copy link
Contributor

Please add a reproduction in order for us to be able to investigate.

Depending on the quality of reproduction steps, this issue may be closed if no reproduction is provided.

Why was this issue marked with the invalid-reproduction label?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository created with create-payload-app@beta -t blank or a forked/branched version of this repository with tests added (more info in the reproduction-guide).

To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue. Ensure your reproduction does not depend on secrets, 3rd party registries, private dependencies, or any other data that cannot be made public. Avoid a reproduction including a whole monorepo (unless relevant to the issue). The easier it is to reproduce the issue, the quicker we can help.

Please test your reproduction against the latest version of Payload to make sure your issue has not already been fixed.

I added a link, why was it still marked?

Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.

Useful Resources

@NeilRiver
Copy link

oh my god yes! (god = Zeus). I thought I was crazy and broke the project again. Yeah! I have the same thing, it just creates empty pages

Image

@yunus-emre-zengin
Copy link

You are probably experiencing the same issue here #11359

A commit for the fix alter merged to main, just wait for the next release

@Girbi
Copy link
Author

Girbi commented Feb 25, 2025

Nice, thank you so much, i didn't find that issue! I will close this.

@Girbi Girbi closed this as completed Feb 25, 2025
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants