Visual editor integration in Next.js App Router
Les mainteneurs répondent en général sous 2 jours
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 30/100
- Type d'issue
- Documentation
- Clarté
- Plutôt claire
- Activité
- À l'abandon
- Stack technique
- next.js, react, typescript
- Domaine
- documentation, web-dev
Piste de recherche
Commencez par lire la documentation existante de l’éditeur visuel de Directus et comparez son approche d’intégration avec les exemples de Next.js App Router et React Server Components fournis ici. Confirmez que les maintainers souhaitent une mise à jour spécifique au framework et conforme à RSC ; le travail est terminé lorsque le guide concerné explique clairement l’approche approuvée et est validé par rapport à la configuration Next.js documentée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Hey Guys,
i recently integrated the directus visual editor in my Next.js App router project.
I have also done the same with other headless CMS, namely Contentful and Storyblok.
Generally, i understand that the goal is to make Guides/Tutorials on the directus docs framework agnostic. However, there is two perspectives from which this task could be implemented framework agnostic. The one being the way it is currently documented, the other being from Next.js perspective, where all visual editors and similar tools are implemented in the same way as well, ever since Next.js moved to App router.
The introduction of React Server Components (RSC) meant a shift in approach for lots of stuff and it is obvious that all services and tools can't change their docs over night to accomodate for this. The original approach of implementing such services into Next.js (and all other frameworks) is now contradicting with the recommended usage of RSC, where all components are meant to be server-side by default.
Therefore, i would advocate for changing the docs regarding this topic to the modern RSC-compliant way.
I am going to give a quick example of what i mean:
import CmsProvider from '@/_lib/cms/provider'
/*
* create a Wrapper component for all additional client-side services and use them in the root layout.
* in this example i created the <CmsProvider> for implementing the directus visual editor
*/
export default async function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="de" suppressHydrationWarning>
<body suppressHydrationWarning>
<CmsProvider>{children}</CmsProvider>
</body>
</html>
)
}
What is the benefit of this?
Well, the concept of RSC implies that client components cannot not contain server components, meaning that any usage of a client component at the top of the component hierarchy, will automatically negate the whole purpose of RSCs.
The only exception to this rule is the root layout, where client-side wrapper components or providers can exist without transforming every child component into a client-side one (even though, this is technically a violation of the rule).
The provider in this case would look somewhere similar to this:
'use client'
import { useEffect } from 'react'
import { usePathname } from 'next/navigation'
import { suspendVisualEditor, initializeVisualEditor } from '@/_lib/cms/visualEditor'
export default function CmsProvider({ children }: { children: React.ReactNode }) {
const pathname = usePathname()
useEffect(() => {
// check if embedded in an iframe
if (typeof window === 'undefined' || window.top === window.self) return
// persist directus embedded status in session storage and toggle draft mode + visual editor accordingly
const isDirectusIframe = document.referrer.includes(process.env.NEXT_PUBLIC_CMS_BASE_URL)
const wasInDirectus = typeof window !== 'undefined' && sessionStorage.getItem('directus-embedded') === '1'
const acceptVisualEditing = isDirectusIframe || wasInDirectus
const hasDirectusCookie = document.cookie.includes('preview_client')
if (acceptVisualEditing && process.env.NEXT_PUBLIC_ENV === 'staging') {
document.body.classList.add('draft-mode')
sessionStorage.setItem('directus-embedded', '1')
// init visual editor if cookie is already present, enable draft mode (sets cookie) otherwise
if (hasDirectusCookie) {
initializeVisualEditor())
} else {
fetch(`/api/draft?slug=${pathname}`)
.then((response) => response.json())
.then((data) => {
console.info('draft mode enabled')
if (!data.redirect) return
initializeVisualEditor()
})
.catch((error) => console.error(error))
}
} else {
document.body.classList.remove('draft-mode')
sessionStorage.removeItem('directus-embedded')
// disable draft mode + suspend visual editor
fetch('/api/draft?disable=true')
.then(() => console.info('draft mode disabled'))
.catch((error) => console.error(error))
suspendVisualEditor()
}
}, [pathname])
return <>{children}</>
}
I would be willing to create a pull request for this, but i wanted to ask beforehand, if this is generally in the spirit of the directus docs.
Cheers!
- Langage dominant
- TypeScript
- Étoiles
- 24
- Forks
- 90
- Merge moyen
- 3 j 22 h
- PR mergées (30 j)
- 19
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de directus/docs
-
Docs Platform
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
directus/docs#88 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
-
llms.txt links agents to /raw/ copies where partials are empty; the inlined .md copies aren't linkedOuverte
Difficulté 3/5 1-2 jours Accessibilité débutants 67/100
directus/docs#865 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
-
Document required special flags per field typePeut-être à nouveau libre Une pull request pour cette issue a été fermée sans être fusionnée. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 58/100
directus/docs#850 · 3 commentaires ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 3/5 1-2 jours Accessibilité débutants 55/100
directus/docs#771 · 3 commentaires ·
Les mainteneurs répondent en général sous 2 jours
-
content-improvement
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
directus/docs#726 · 3 commentaires ·
Les mainteneurs répondent en général sous 2 jours
Toutes les issues de directus/docs
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
ranxianglei/billion-context#7597 ·
Les mainteneurs répondent en général sous 1 jour
-
kubernetes-ingestor: fetchCRDMapping() runs even when crossplane.enabled is false, logging a 403 ERROR every runPeut-être pris @kc9ddi l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
TeraSky-OSS/backstage-plugins#228 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
zmkfirmware/zmk#3571 ·
Les mainteneurs répondent en général sous 10 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
[Windows] Hidden title bar: a maximized window restored from minimized on a secondary monitor gets the primary monitor's work area as its client areaPeut-être pris @lijy91 l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
libnativeapi/nativeapi#53 · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour