question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RFC: Port SliceZone to Next.js

See original GitHub issue

Part of the port of SliceMachine to Next consists in porting the SliceZone.

What’s a SliceZone

A component that matches front-end components with Prismic data components (that we call slices). You can see it as an hybrid between a “components registry” and a router:

  • at build time, it scans and lists available components to create a custom resolver function
  • when a page hits, it fetches the corresponding content on Prismic
  • it then matches Prismic slices with components, and renders them accordingly

Features

  • Auto-fetch Prismic data
  • Auto-match components
  • Theme (via context or props)
  • Vue slots-like pattern

Static export and differences with Nuxt

Next 9.3 introduced getStaticProps to pre-render pages at build time. Instead of relying on a PageFetch wrapper component, the next-slicezone exports a useGetStaticProps function that formats arguments and returns a Next getStaticProps function.

The Nuxt module makes use of Nuxt templating to create the resolver function. A more idiomatic way to handle such cases in Next would be to create the registry (an object with components ids and paths) at getStaticPaths call and pass it down. The SliceZone would then pick up the registry and make calls to loadableComponents.

On slots

The Nuxt SliceZone makes use of Vue named-slots. When working with external libraries like essential slices, a common pattern is to defer part of the renderers to the user. Different solutions exist in React (notably render props pattern), and we might offer several.

Example page

This is subject to change, especially regarding how/where Prismic client is instantiated.

import { Client } from '../prismic'
import SliceZone, { useGetStaticProps, useGetStaticPaths } from 'next-slicezone'


const Page = ({ uid, registry, slices }) => (
  <div>
    <h1 className="title">
      Welcome to page "{uid}"!
    </h1>
	<SliceZone registry={registry} slices={slices} />
  </div>
)

export const getStaticProps = useGetStaticProps({
  client: Client(),
  uid: ({ params }) => params.uid
})

export const getStaticPaths = useGetStaticPaths({
  client: Client(),
  type: 'page',
  fallback: true,
  formatPaths: ({ uid }) => `/${uid}`
})

export default Page

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
hypervillaincommented, Jun 9, 2020

I’ll add a section regarding scan & match. I’ve described how the filesystem is scanned here in the meantime: https://github.com/prismicio/slice-machine/tree/master/packages/vue-slicezone#auto-match-components

1reaction
sadachecommented, Jun 9, 2020

@hypervillain also can you please add (for context) an example of the syntax for declaring a SliceZone in a Next page? 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Slice Machine Iteration 8 June 2020 - Pull command & Next.js ...
We are porting Slicemachine to next.js means three things. Porting the Slicezone to next.js; Automating the configuration ... RFC: Port SliceZone to Next.js....
Read more >
next-slicezone - npm
A component that maps other components to Prismic slices. Latest version: 0.2.6, last published: 8 months ago. Start using next-slicezone in ...
Read more >
next.js - How to specify a port to run start slicemachine app on
So I found myself in a situation where I want to have 2 slice machines working simultaneously on different ports. Does someone know...
Read more >
Untitled
Gustakh dil episode 105, Franklin harbour council minutes. ... Diavolo della tasmania immagini, Javascript disable title tooltip, Star breakers carrickmore, ...
Read more >
instances.tsv - Free Speech Extremist
... down 159.69.149.126 music.selea.se down 81.235.28.5 next.teamlifezone.ru ... mastodon 3.4.1+glitch js.social down 76.76.21.21 drive.realsecure.eu down ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found