#Fallback to default locale gives error

1 messages · Page 1 of 1 (latest)

stiff dew
#

In the image you can see the checkbox I check, and when I do, I get this error:

    err: {
      "type": "CastError",
      "message": "Cast to embedded failed for value \"true\" (type boolean) at path \"en\" because of \"ObjectParameterError\"",
      "stack":
          CastError: Cast to embedded failed for value "true" (type boolean) at path "en" because of "ObjectParameterError"
              at SchemaDocumentArray.cast (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__/node_modules/mongoose/lib/schema/documentArray.js:501:19)
              at SchemaDocumentArray.cast (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__/node_modules/mongoose/lib/schema/documentArray.js:426:17)
#####MORE...#####

I saved and got the error, then reloaded the page and now I can't even open the footer page in the cms using en, I can only open using sv, I get this error:
[20:23:21] ERROR: Cannot create property 'id' on boolean 'false'

drifting fractalBOT
stiff dew
#

This is what the structure looks like in mongo db:

untold drift
#

Can you share your collection config and Payload version please

stiff dew
#

ofcourse, here is my footer config:

import type { GlobalConfig } from 'payload'

import { revalidateFooter } from './hooks/revalidateFooter'
import { link } from '@/fields/link'

export const Footer: GlobalConfig = {
  slug: 'footer',
  admin: {
    description: 'Footer är den del längst ner på hemsidan',
  },

  access: {
    read: () => true,
  },
  fields: [
    {
      name: 'logo',
      label: 'Logga',
      type: 'upload',
      relationTo: 'media',
      required: true,
    },
    {
      name: 'navCategory',
      label: 'Kategori med länkar',
      type: 'array',
      fields: [
        {
          name: 'category',
          label: 'Kategori',
          type: 'text',
          required: true,
        },
        {
          name: 'navItems',
          label: 'Länkar',
          type: 'array',
          fields: [
            link({
              appearances: false,
            }),
          ],
          maxRows: 6,
          admin: {
            initCollapsed: true,
            components: {
              RowLabel: '@/Footer/RowLabel#RowLabel',
            },
          },
        },
      ],
      localized: true,
    },
  ],
  hooks: {
    afterChange: [revalidateFooter],
  },
}
#

package.json:

{
  "name": "",
  "version": "1.0.0",
  "description": "A blank template to get started with Payload 3.0",
  "license": "MIT",
  "type": "module",
  "scripts": {
    "build": "cross-env NODE_OPTIONS=--no-deprecation next build",
    "dev": "cross-env NODE_OPTIONS=--no-deprecation next dev",
    "devsafe": "rm -rf .next && cross-env NODE_OPTIONS=--no-deprecation next dev",
    "generate:importmap": "cross-env NODE_OPTIONS=--no-deprecation payload generate:importmap",
    "generate:types": "cross-env NODE_OPTIONS=--no-deprecation payload generate:types",
    "lint": "cross-env NODE_OPTIONS=--no-deprecation next lint",
    "payload": "cross-env NODE_OPTIONS=--no-deprecation payload",
    "start": "cross-env NODE_OPTIONS=--no-deprecation next start"
  },
  "dependencies": {
    "@payloadcms/db-mongodb": "latest",
    "@payloadcms/next": "latest",
    "@payloadcms/payload-cloud": "latest",
    "@payloadcms/richtext-lexical": "latest",
    "@payloadcms/storage-s3": "^3.14.0",
    "@payloadcms/ui": "latest",
    "cross-env": "^7.0.3",
    "graphql": "^16.10.0",
    "next": "15.1.0",
    "payload": "latest",
    "react": "19.0.0",
    "react-dom": "19.0.0",
    "sharp": "0.32.6"
  },
  "devDependencies": {
    "@eslint/eslintrc": "^3.2.0",
    "@types/node": "^22.10.5",
    "@types/react": "19.0.1",
    "@types/react-dom": "19.0.1",
    "autoprefixer": "^10.4.20",
    "eslint": "^9.17.0",
    "eslint-config-next": "15.1.0",
    "postcss": "^8.4.49",
    "prettier": "^3.4.2",
    "tailwindcss": "^3.4.17",
    "typescript": "5.7.2"
  },
  "engines": {
    "node": "^18.20.2 || >=20.9.0"
  }
}
#

wait sorry, here is the buildconfig, I accedentially sent the footer config:

// storage-adapter-import-placeholder
import { mongooseAdapter } from '@payloadcms/db-mongodb'
import { payloadCloudPlugin } from '@payloadcms/payload-cloud'
import { lexicalEditor } from '@payloadcms/richtext-lexical'
import { s3Storage } from '@payloadcms/storage-s3'
import path from 'path'
import { buildConfig } from 'payload'
import { fileURLToPath } from 'url'
import sharp from 'sharp'

import { Users } from './collections/Users'
import { Media } from './collections/Media'
import { Header } from './Header/config'
import { Footer } from './Footer/config'
import { Pages } from './collections/Pages'

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

export default buildConfig({
  admin: {
    user: Users.slug,
    importMap: {
      baseDir: path.resolve(dirname),
    },
  },
  collections: [Users, Media, Pages],
  editor: lexicalEditor(),
  secret: process.env.PAYLOAD_SECRET || '',
  typescript: {
    outputFile: path.resolve(dirname, 'payload-types.ts'),
  },
  db: mongooseAdapter({
    url: process.env.DATABASE_URI || '',
  }),
  globals: [Header, Footer],
  sharp,
  localization: {
    locales: ['sv', 'en'],
    defaultLocale: 'sv',
  },
  plugins: [
    payloadCloudPlugin(),
    s3Storage({
      collections: {
        media: {
          prefix: 'media',
          disablePayloadAccessControl: true,
        },
      },

      bucket: process.env.S3_BUCKET || '',
      config: {
        credentials: {
          accessKeyId: process.env.S3_ACCESS_KEY_ID || '',
          secretAccessKey: process.env.S3_SECRET_ACCESS_KEY || '',
        },
        region: process.env.S3_REGION,
        endpoint: process.env.S3_ENDPOINT,
        forcePathStyle: true,
      },
    }),
  ],
})

untold drift
#

I'm not sure where that checkbox is coming from tbh, is it from the link?

stiff dew
#

oh I though that was a feature from payload? because I have just started with the blank payload template and added some things

#

someone else seems to be having the same checkbox in another message in discrod:

#

not the same problem though

#

it is not only in the footer, it seems to be everywhere when changing from sv to en

untold drift
#

Hmm yeah that's applied by Payload my mistake, not sure what's happening here tbh

#

I'd try to reproduce in a fresh project, and if you're able to do so then create an issue

stiff dew
#

okay thank you 🙂 I have some projects that has to be done for some clients so sadly I don't have the time for that atm, but thank you for your time

lucid marsh
lucid marsh
magic monolith
# lucid marsh ```export const fixDefaultLocale: CollectionBeforeChangeHook = async ({ data }) ...

Where would you put this? I am having a similar problem with "Fallback to default locale" checkbox in my Page collection but I don't understand what is really the correct data I should be submitting here.

I've attached my logging on beforeChange hook and when saving in a different locale would it not be correct to pass in the blocks of the english data instead of false here?

Edit:

      data.blocks = data.blocks === true ? null : data.blocks;
      console.log('data', data)
      return data

I ended putting this in my beforeChange hook copying you and it seems to correctly set the blocks now for my other language. Is this a bug in PL that needs to be fixed?

upper kindle
lucid marsh