Migrating Legacy Slices to Slice Machine - Question on Legacy Slice Names

Hi there,

My site is currently using legacy slices with NextJS. On a single custom type in my repository, I've been trying out the beta tool for migrating legacy slices. Everything seems to have worked well, but it looks like the custom type within the Prismic editor holds a reference to the old slice name even after I've pushed up my slice machine migrations.

As an example, my old legacy slice was called "simple_section". When migrating my slice in Slice Machine, it auto-filled to the name "SimpleSection" and I just went with it. I realized this was a problem when I tried to render the slice using the SliceZone component. It gave me the following message:

[SliceZone] Could not find a component for Slice type "simple_section"

Looking at the slice_type in the returned data, I can see that it is giving me the old name which is causing the error:

{
  ...,
  slice_type: 'simple_section'
}

Taking a look at the rest of my slices, it looks like I have followed the same "underscore" naming convention for some reason. With this one page I've tested, is it safe to edit the JSON to match the legacy slice name or will it be easier to republish this document so that the name references might be updated automatically?

While continuing with my migration, I imagine it will be much simpler to match the names of my old slices exactly so that this doesn't happen. My main question is - is this the intended behavior of the migration or is this an edge case that I may have found? It would be nice to not have the mental overhead of matching names exactly when migrating though.

Thanks!

Hi @crcollver thanks for sharing your detailed thoughts and questions on the slice migration process and sorry for getting back so late to you - we had a quirk in our reply process

With this one page I've tested, is it safe to edit the JSON to match the legacy slice name or will it be easier to republish this document so that the name references might be updated automatically?

Republishing the document should update the slice ID reference following your migration (this will create a new master ref in your API which should update other occurrences also)

We don't recommend manually editing JSON models, although it is something possible to do that should also work. If you want to try doing so, it's preferable for it to happen before pushing anything to Prismic (related to that change). Doing it after the slice was pushed to Prismic could lead to unexpected side effects if you've worked with documents featuring that slice in between.

I imagine it will be much simpler to match the names of my old slices exactly so that this doesn't happen. My main question is - is this the intended behavior of the migration or is this an edge case that I may have found?

Trying to match your old slice names is a valid approach, however, it shouldn't be an issue to use other names. The API response should update once a document is published after the updated slice was pushed (again, this creates a new master ref triggering the update process).

Let us know if this helps you, and sorry again for the delay!

Hi @lihbr, thank you for the clarification. That helps to know that republishing should update the model.

For large numbers of documents, what is the recommended way to do this? I was trying out the Migration API, but it looks like the document must be republished before I'm able to make any modifications using this API since the model needs to be updated.

Currently, my site is small enough for this to not be a huge issue, but it would be nice to avoid the manual work in the future.

Thanks!

Hi @crcollver

Migrating old slices to shared slices is recommended to be done through Slice Machine with the UI you used independently of your repository size. You shouldn't need to republish all your documents after doing so, just republishing one should be enough.

Let us know if that clarifies better the process for you :smiling_face:

1 Like