What is the problem to solve?

Frontend developers not coming from Drupal usually do not know Twig. By providing support for multiple frontend frameworks we could provide support for modern JavaScript frameworks like React, Vue or Astro besides Twig. This would make Drupal a much more attractive option for those developers and evaluators, since it's not necessary to re-train frontend developers on Drupal.
The modern frontend option would allow building sites with high-interactivity with modern JavaScript frameworks without a fully decoupling, like inertia.js does for Laravel.

Who is this for?

Frontend developers not familiar with Drupal, evaluators.

Result: what will be the outcome?

Re-architect Drupal such that the frontend rendering process is not coupled with the rest of Drupal. Make Drupal render into a tree of high-level components and add page metadata, then let the frontend take care of rendering those. The tree must be pure data (e.g. JSON) and provided via some HTTP API by page, e.g. /page-api/{path}. Frontends fetch this API and render the result, either server or client-side.

By default, Drupal core could ship with a twig-based frontend which uses symfony request/responses to internally resolve http requests without network overhead. The rendering happens de-coupled from the rest of the application, thus any lazy-rendering would have to trigger another (internal) http request.

Next to twig, we could provide one or two JavaScript based frontend frameworks which are officially supported, while the community could add more. CMS builders working with core could choose their preferred frontend framework or even allow site-builders to choose from supported options.

Implementation example

Lupus Decoupled Drupal already follows that model, but does not implement a twig-based frontend. Still, it can serve as some example that a core implementation could learn from. Here is some documentation about its page API and here is real-life example of it. Read about it here: https://drunomics.com/en/blog/inertiajs-style-development-drupal-lupus-d...

Implementation strategies

a) Follow the approach of the Semi-Coupled theme engine of XB: Make a mapping of render array to components.
b) Propagate a clear cut and build a new render API that only supports the desired component model (and simplify as much possible). Add a compatibility layer for rendering render arrays into the component model like in a). Slowly phase the current render API out, after long deprecation.

Lupus Decoupled Drupal implements a new component model via the https://www.drupal.org/project/custom_elements module. https://lupus-decoupled.org/get-started/how-it-works describes how it works.

Pros/Cons

Advantages that come with this approach:
- Drupal backend and frontend can be developed and tested separately
- Drupal stays in the driving seat, pages are composed by Drupal
- A HTTP-endpoint for the page API allows frontend-developers to easily introspect what is there to render. Great dev-tools could be built on top of that.
- Allows frontend developers to bring modern frontend (templates, components and tooling) to Drupal

Disadvantage:
- JSON-API / API-first is not required. Still developers it's an important addition, such that it's easy to fully decouple parts (or the full) application when preferred.
- Frontend stacks might have to support lots of components to be complete. A fallback mechanism would be great.

How can we know the desired result is achieved

* Drupal core provides an HTTP API for fetching the component-tree of a page
* Drupal core provides a twig/sdc-based frontend based on the component-tree
* Drupal core provides at least one modern JavaScript frontend option, that allows for either server or client-side rendering.

CommentFileSizeAuthor
#10 Screenshot 2025-05-07 215034.png79.08 KBsupriyagupta

Issue fork drupal-3506337

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

fago created an issue. See original summary.

fago’s picture

Issue summary: View changes
fago’s picture

Issue summary: View changes
fago’s picture

Issue summary: View changes
quietone’s picture

Project: Drupal core ideas » Drupal core
Version: » 11.x-dev
Component: Idea » other
Category: Task » Feature request

The Ideas project is being deprecated. This issue is moved to the Drupal project. Check that the selected component is correct. Also, add the relevant tags, especially any 'needs manager review' tags.

Thanks

quietone’s picture

catch’s picture

b) Propagate a clear cut and build a new render API that only supports the desired component model (and simplify as much possible). Add a compatibility layer for rendering render arrays into the component model like in a). Slowly phase the current render API out, after long deprecation.

For simplification, see @pdureau's comment on #2702061-106: Unify & simplify render & theme system: component-based rendering (enables pattern library, style guides, interface previews, client-side re-rendering) which would drastically reduce the number of #type and #theme, concentrating on #type => component pointing to SDCs, and possibly remove the preprocess layer. I think we should be doing that independently of anything here, and it also might turn out to be a hard pre-requisite.

fago’s picture

Thank you for the pointer! I've commented on the other issue.

For keeping this issue up2date, I'm also crossposting here. I think #2702061: Unify & simplify render & theme system: component-based rendering (enables pattern library, style guides, interface previews, client-side re-rendering) would be the perfect first step for going towards a multi-frontend architecture. As I commented at #2702061-114: Unify & simplify render & theme system: component-based rendering (enables pattern library, style guides, interface previews, client-side re-rendering) we need to have a 2nd-step through to entangle the control flow such that we are able to generate a complete tree of components first and render it in a 2nd step. Once we have that we can also serve it via an HTTP API for a) multi-frontend usage and b) better debugging XP.

supriyagupta’s picture

https://www.drupal.org/u/fago Thanks for all the great work and discussions here! I've created a custom module that builds on these ideas — it generates a full component tree for any entity and supports rendering it in a second step. The structure is designed to support multi-frontend use cases (Twig, React, etc.) and can serve the tree via an HTTP API for better debugging and decoupled rendering.

I'd love to contribute and test this approach with others who are interested. Please let me know if you'd be open to reviewing or trying it out! for reference attached image response

supriyagupta’s picture

StatusFileSize
new79.08 KB
larowlan’s picture

Thinking about this somewhat, the default rendering of Drupal is to HTML.
But that is a serialization format. JSON is another.

Perhaps if we reworked the renderer so that all of the processing aspects were part of 'normalizing' and then the render array to HTML was 'serializing' we could support serializing to JSON and other formats for render arrays.

These sound like the 2 steps you're talking about in #8 @fago

We already have these concepts for entities, but not for render arrays (which with #3525331: Reuse element plugins as object wrappers around render arrays start to move towards objects anyway).

This was the same approach I proposed in #3467499: Use a custom serialization format instead of theming to render the edit form to the intermediary representation that XB's React code consumes

andypost’s picture

Generally speaking nowadays probably Markdown is another demanded format, it can provide YAML in "frontmatter" and text render
IMO it's more demanded to allows LLMs read sites, other option could be Abstract Syntax Tree (maybe someone's summer project)

fago’s picture

Perhaps if we reworked the renderer so that all of the processing aspects were part of 'normalizing' and then the render array to HTML was 'serializing' we could support serializing to JSON and other formats for render arrays.

These sound like the 2 steps you're talking about in #8 @fago

yes! that would perfectly fit and allow other frontends to work with the serialized JSON response to implement alternating render strategies.

supriyagupta’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Sorry this is clearly AI writing a custom module

catch’s picture

Status: Needs work » Active

I'm hiding the branch and the MR, that is not just AI slop but also off topic AI slop.

catch changed the visibility of the branch 3506337--make-drupal to hidden.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.