Content Relationships and Slice Machine

Hi I managed to get my slices to work with content relationships but slice simulator isn't receiving this data so I can't preview data or get screenshots.

I have a testimonials slice that pulls in data from a testimonials custom type.

I am using Prismic with NextJS.

My homepage is coded like this.

import { createClient } from '../prismicio';
import { SliceZone } from '@prismicio/react';
import { components } from '../slices/index';

import Layout from '../components/Layout';

export default function Home({ layout, home }) {
	return (
		<Layout layout={layout}>
			<SliceZone
				slices={home.data.slices}
				components={components}
			/>
		</Layout>
	);
}

export async function getStaticProps({ params, previewData }) {
	const client = createClient({ previewData });

	const layout = await client.getSingle('layout');
	const home = await client.getSingle('homepage', {
		fetchLinks: 'testimonials.testimonial',
	});

	return {
		props: {
			layout,
			home,
		},
	};
}

I am pulling in data in my slice with

slice.primary.testimonialRelationships.data.testimonial

I works fine when I view page as a whole at localhost:3000 but when in slice simulator (even for other slices now) I'm getting this error.

TypeError: Cannot read properties of undefined (reading 'testimonial')

1 Like

Hi Roy,

Mock data for content relationships is not possible in Slice Machine at the moment, the team are planning to work on this very soon. This is being tracked as a feature request here:

For now you will only be able to test this with Published content in your Prismic repository.

Thanks.

2 Likes

Hi Phil,

what is the current status of this feature?
it's crucial feature for me as I can't do screenshot and test my slices via slicemachine.

Best
Mateusz

There has been no change in the release status of this feature. For now it's only possible to test with live content and add Custom screenshots.

With the addition of Live Previews in the Prismic admin this feels more pressing. We've got many slices that are built around content relationships, right now those all just render as blanks or error messages.

Hi Sam,

Thanks for your message. We are aware of this issue and have it on our list of feature improvement but we can't share an expected release date for now. The team has recently fixed part of this issue when content relationship fields where used to only link internal pages, but we still don't support the usage of content relationship fields that fetch specific data from another document.

Best,

Côme, Devtools team at Prismic

1 Like