Replacing old slices with SM slices

Sorry, this post is a little scattered but I'm kinda feeling around in the dark...

I'm migrating an existing site to slicemachine. I created a new shared component called "Hero" - there was an existing slice on Page called "Hero".

In slicemachine ui - it showed them as 2 separate options

When I pushed the slice, it seems to have replaced the slice, and removed the slices out of the content pages the old one was referenced on. (note i had changed a couple field names, the old fields had underscores which aren't allowed anymore)

Could I get some insight into what's going on behind the scenes so I can plan accordingly?

Does pushing a same-named shared-slice always replace the slice and remove it from all the content that references it?

Do both slices technically exist and one is just hiding? If I rename the new Hero, will the old one still be there?

Thanks

Hey Beamer, I'll need to reproduce the use case on my end to see if there's a reason for this and/or a workaround to fix it. I'll come back as soon as possible.

Thanks

Hey there, I can confirm that, for the moment, this is the expected behavior of the Shared Slices library. When you create a Slice with the same name in Slice Machine and in the retro Prismic editor, they will conflict and the one created in Slice Machine will take preference.

I added a feature request to make this clear with a note or warning. Sorry for the inconvenience.

@Pau Ok - is the best scenario here calling them like SMHero and renaming them after? or is that going to make a mess?

The other alternative is setting up a new repo and migrating all the content over

Yes, giving it a totally different name can solve the problem, because it just treats it as a different Slice. You can use the same repository. it is true that migrating from the old editor to the new one is still not a smooth and automated process. We are continuously working to improve this process.

What's the process for renaming a SM slice and renaming it back?

My options how I see it:

Rename Local Slices

  1. Rename my local unpublished slices from { id: "title", name: "Title" } to { id: "sm_title", name: "SMTitle"}
  2. (?) is id the only key that matters to avoid overwriting?
  3. Go through each doc and slowly add the new slices and remove the old ones
  4. (?) Go back and rename the slices? I'm guessing this will cause naming conflicts?

Rename Remote Slices

  1. Rename existing (old) slices in Prismic Title => OldTitle
  2. Publish new sm slices
  3. Go through each doc and slowly add the new slices and remove the old ones

Create new repo and start over

  1. The hardest part with this is moving over the uploaded media - is this something that Prismic can copy to another repo behind the scenes? The content I can recreate, but the images are a pain.
  2. Or duplicate an entire repo, and I'll just delete the old stuff

Is there any insight you have on this @Pau? I don't want to wipe a model or any content during a rename or that'd put me back to square one.

Honestly I only have 10 slices/30 pages, so this isn't a big deal, I just want to figure out the non destructive way to do this, as the project is currently in production

Thank you!

I consider that the easiest way to make the transition from old to new Slices (SM), for now, is to use different names from the beginning. So you don’t need to deal with the tedious process of renaming the ones you’ve already created locally with the Custom types API. And so you can migrate everything in a repository that already has the content.

@pau ok that's no problem. How do you rename the shared slices after the migration? Just change the model.json name? Sounds scary :slight_smile:

Ok I've messed around a bit more and here's what I've found:

  1. Made a blank repo
  2. Create a traditional slice in Prismic UI called "Test"
  3. Created a local SM slice called "Test"
  4. Changed the id from test to sm_test, and the name to SMTest
  5. SM kinda breaks unless i rename the component to SMTest to match the name, so I did that
  6. Add to Page and push to prismic - now have 2 slices, Test and SMTest in Page. Great
  7. Create content, mess around
  8. Rename component from SMTest to Test
  9. In model - name: "Test" and leave id set to sm_test
  10. Publish
  11. [slice-machine] [slice/push] Slice Test: Unexpected error returned. Server message: CONFLICT: sm_test already exists.

My guess: it's trying to create a new slice since name is different (vs update). If that's true it's not going to work for me.

I think I'm going down the wrong path. I'm likely going to have to create a new repo and do this all manually :frowning: c'est la vie

For the moment there isn't a standardized way of doing these changes.

We don't recommend renaming any model in the json model, the best way of doing this is to name the Slices a different name from the beginning, in Slice Machine. I understand that this may not be ideal in terms of UI, since it doesn't allow you to have the naming conventions you want. But it is the best option at the moment. We even have another open feature request for this: