prismicio / prismic-react

React components and hooks to fetch and present Prismic content
https://prismic.io/docs/technologies/homepage-reactjs
Apache License 2.0
153 stars 40 forks source link

Being Framework agnostic #183

Open loick opened 11 months ago

loick commented 11 months ago

Is your feature request related to a problem? Please describe.

I'm working on a monorepo with several apps, and having a dedicated adapter to a specific framework is not flexible enough for me.

Describe the solution you'd like

Right now, I'm using (mainly) nextJS with the new prismic adapter. I migrated all of the methods using "prismicio/next" from my CMS package I created in order to be as agnostic as possible. I'm still using two remaining methods from this package that I would like to get rid of (to stick to nodeJS / React but not to nextJS):

Also, when I create a new slice because of the next adapter, I get an index file using 'next/dynamic'. I would like to be able to stick to a classical export components file without any relationship with nextJS as well.

Obviously I would like to keep the same features (previews etc.).

Do you have any idea on how to achieve this?

Thanks!

lihbr commented 11 months ago

Hey Loïck, thanks for contributing!

You can disable Next-specific lazy-loading within your slicemachine.config.json through your adapter options:

{
  "repositoryName": "...",
  "adapter": {
    "resolve": "@slicemachine/adapter-next",
    "options": {
      "lazyLoadSlices": true
    }
  },
  "libraries": [ /* ... */ ]
}

More on that here: https://prismic.io/docs/technical-reference/slicemachine-adapter-next?version=0.1#usage

I'll let @angeloashmore get back to you on the preview-specific nitty gritty~

loick commented 11 months ago

Nice indeed, good catch, I didn't see this option. 👍

Now only the preview stuffs remain

angeloashmore commented 11 months ago

Hey @loick,

Previews will likely require some framework-specific code since previews affect how you query for content. Content querying is typically framework-specific when using the most performant method.

In Next.js, for example, you would need to use Preview Mode in the Pages Router or read cookies() in the App Router. In both cases, there wouldn't be a framework-agnostic way to integrate previews unless you fetched all of your content on the client, which we do not recommend.

That being said, here are the tools you have available to implement previews:

Next.js (@prismicio/next) (docs)

React (@prismicio/react) (docs)

JavaScript/TypeScript (@prismicio/client) (docs)

This repository, @prismicio/react, is designed to be agnostic for any React application. @prismicio/next is more specific and designed to work only in Next.js applications. @prismicio/client is the most general of the three and is designed to be agnostic for any JavaScript project.

Let me know if you have any questions!

loick commented 10 months ago

Hi, and thanks for your answer!

Related to previews, I guess the code could be generic to accept any frameworks. For example, this component basically depends more on router methods than Next / Nuxt right?