prismicio / slice-machine

A series of tools for developing and deploying website sections with Prismic
https://prismic.io/docs
Apache License 2.0
287 stars 53 forks source link

RFC: Add Gatsby support to Slice Machine #331

Closed angeloashmore closed 1 year ago

angeloashmore commented 2 years ago

Overview

This RFC describes how Gatsby support could be added to Slice Machine.

Gatsby’s focus on static site generation and its internal GraphQL API presents challenges that do not exist in Next.js and Nuxt.

What and/or who is affected by this RFC?

Why is this being proposed?

Going forward, Slice Machine is the primary method to develop websites with Prismic. Currently, Slice Machine only officially supports Next.js and Nuxt. Gatsby has a large user base, but its users are unable to use Slice Machine (in an officially supported way).

Background Information

What is the current situation?

Today, Gatsby users can use Prismic in one of the two methods:

  1. Use the Writing Room Custom Type editor

    This is the “classic” method of building Custom Types and Slices. Slices cannot be dynamically shared between Custom Types. Isolated development environments, such as developing Slice components, must be set up independently. In most cases, this involves using Storybook ad hoc.

  2. Use Slice Machine in an unsupported fashion

    Slice Machine can be configured to use a universal “none” framework that disables component file generation and the Slice Simulator environment. This leaves Slice Machine as only a local Custom Type model builder and excludes its main benefits.

Slice Machine can also be “misconfigured” to use the Next.js integration (in a Gatsby site). The files that are produced are Next.js-specific, which means it lacks required code like GraphQL fragments for Slices.

Option #1 is the documented method of using Prismic with Gatsby. Option #2 is undocumented and not recommended.

What are the current problems?

As mentioned in the intro, Gatsby’s focus on static site generation and its internal GraphQL API presents challenges that do not exist in Next.js and Nuxt.

The extra GraphQL layer introduced by Gatsby creates a mis-match between Slice Machine’s generated mock files (which mimic Prismic’s Rest API V2) and Gatsby’s GraphQL API (which alters Prismic’s Rest API V2 data via gatsby-source-prismic).

Are there any related discussions from elsewhere?

A basic PR to add Gatsby support was opened back in July 2021 (see here). Since then, Slice Machine has been rearchitected, requiring changes to the PR.

Part of this PR involved updating gatsby-source-prismic and gatsby-plugin-prismic-previews to support Shared Slices. This work is complete and does not need further changes.

There is also interest from the community to provide Gatsby support, as seen in #277.

Proposal

Completing this effort ideally can be completed within two weeks of development time (documentation may take additional time).

This timeframe is given to help guide technical decisions. Supporting 90% of use cases in a short timeframe is favored over covering 100% of use cases in an extended timeframe.

Adding Gatsby support requires the following:

Slice Simulator

Define how Slice Simulator is set up in a Gatsby project.

Setup steps

Write clear setup steps that appear in Slice Machine’s sidebar. See how this works for Next.

Gatsby-specific component template

Create an updated Slice component template file that uses the latest version of @prismicio/react and includes a basic GraphQL fragment. See how this works for Next.

Documentation

Updated documentation for using Slice Machine with Gatsby (and ideally becomes the primary method).

gatsby-source-prismic integration

Expose an easy to way provide Custom Type and Shared Slice models to gatsby-source-prismic. The plugin already accepts the JSON models as plugin options, but loading these JSON models is not currently automated in any way.

How it could be implemented

See the outdated PR for a general idea of an implementation strategy.

Also see this example project for a fully working example (using the not working, outdated PR).

The following portions of the example project are noteworthy:

How to provide feedback

Anyone can provide feedback on everything mentioned in this RFC. If you have any thoughts or would like to see specific feature implemented, please comment on this issue.

If you are also interested in contributing code, please let me know!

Thanks! 😄

hypervillain commented 1 year ago

Closing for now after the new plugins architecture release