Describe your question/issue in detail
I am in the process of removing a slice completely from my project since I am not using it anymore. I deleted the slice via slice machine and pushed the changes, but it seems that the slice data is still being returned as part of the API call.
This is how I am calling the information:
import { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { SliceZone } from '@prismicio/react';
import { createClient } from '@/prismicio';
import { components } from '@/slices';
type Params = { uid: string };
export default async function Page({ params }: { params: Params }) {
const client = createClient();
const page = await client.getByUID('article', params.uid).catch(() => notFound());
console.log(page.data.slices);
return (
...
);
}
export async function generateMetadata({ params }: { params: Params }): Promise<Metadata> {
const client = createClient();
const page = await client.getByUID('article', params.uid).catch(() => notFound());
return {
title: page.data.meta_title,
description: page.data.meta_description,
};
}
export async function generateStaticParams() {
const client = createClient();
const pages = await client.getAllByType('article');
return pages.map((page) => ({ uid: page.uid }));
}
And the output of console.log(page.data.slices)
:
[
{
variation: 'default',
version: 'initial',
items: [],
primary: {},
id: 'expected_a$123',
slice_type: 'expected_a',
slice_label: null
},
{
variation: 'default',
version: 'initial',
items: [ [Object], [Object], [Object] ],
primary: {},
id: 'unexpected$123',
slice_type: 'unexpected', // Deleted slice type shows up
slice_label: null
},
{
variation: 'default',
version: 'initial',
items: [],
primary: { title: [Array] },
id: 'expected_b$123',
slice_type: 'expected_b,
slice_label: null
},
{
variation: 'default',
version: 'initial',
items: [ [Object] ],
primary: {},
id: 'expected_c$123',
slice_type: 'expected_c',
slice_label: null
}
]
[SliceZone] Could not find a component for Slice type "unexpected" {
variation: 'default',
version: 'initial',
items: [...],
primary: {},
id: 'unexpected$123',
slice_type: 'unexpected',
slice_label: null
}
Because of this, the default 'slice not found' message is now visible on the UI: Could not find a component for Slice type “unexpected”
Impacted feature
Slice machine
What steps have you taken to resolve this issue already?
-
Restart slice machine and dev environment
I assume it has to be a cache issue, so I restarted the environments but this did not solve the issue. -
Clear browser cache (Chrome)
Perhaps it has to do with the browser, so I cleared the browser cache but it did not solve the issue either. -
Explicit hard code a filter to exclude the offending slice type
const filterOutOffendingSlice = async ( page: Document ) => page.data.slices.filter((slice) => slice.slice_type !== 'unexpected');
This throws a Type error:
This comparison appears to be unintentional because the types '"expected_a" | "expected_b" | "expected_c" and '"unexpected"' have no overlap.
Which is expected because pushing the changes via slicemachine updates the type declaration in prismicio-types.d.ts
,
Hence, I am now stuck because Prismic is returning information of a slice that does not exist anymore.
These are the prismic versions I am using:
"@prismicio/client": "^7.3.1", "@prismicio/next": "^1.5.0", "@prismicio/react": "^2.7.3",
Slice Machine is running on v1.24.0
.
Assistance or advice will be greatly appreciated.
Thank you!