Relationship/Upload causing page refresh

default discord avatar
.redjoker
3 months ago
6

Dealing with this issue locally running

yarn dev

on Payload v1.8.2.



Expected: Based on the Payload Demo when on a "page" I click "Upload new media" on an upload field it should open an upload modal and let me add one, then I can close the modal with the media relationship set. No page transition.



What happens: When I open the media modal it refreshes the page and changes the route to the media collection. Clicking "back" in the browser it takes me to my "page" collections listings.



import { CollectionConfig } from 'payload/types';

const Media: CollectionConfig = {
  slug: 'media',
  versions: {
    drafts: {
      autosave: true,
    }
  },
  admin: {
    useAsTitle: 'filename',
    group: 'Content',
  },
  upload: {
    staticURL: '/media',
    staticDir: 'assets',
    imageSizes: [
      {
        name: 'thumbnail',
        width: 400,
        height: 300,
        position: 'center',
      },
    ],
    adminThumbnail: 'thumbnail',
    mimeTypes: ['image/*'],
  },
  fields: [
    {
      name: 'alt',
      type: 'text',
    },
  ],
};

export default Media;
  • default discord avatar
    notchr
    3 months ago

    Hello @.redjoker - that is odd, what version of Payload are you on?

  • default discord avatar
    .redjoker
    3 months ago

    Payload v1.8.2

  • default discord avatar
    notchr
    3 months ago

    Hmm, okay, do you get any errors in dev tools?

  • default discord avatar
    .redjoker
    3 months ago

    No error when I click "upload new media" from the "page" collection.



    I figured it out! Turns out you shouldn't set your media to have the versioning config. The autosave was causing issues.



    (You can still use drafts)

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.