Drupal Canvas Code Components: How Front-End Developers Contribute With React

Drupal Canvas code components let front-end developers write JSX and CSS that marketers then place on pages without raising a ticket. Canvas renders them with Preact and its React compatibility layer. Developers can work in the browser editor or a local codebase, and stable releases fall under Drupal's security advisory policy.

‍

Key Takeaways

  • Code components are your own JavaScript and CSS, managed in Canvas and rendered with Preact.
  • Use the browser editor for changes inside one component. Use a local codebase for new files, assets or dependencies.
  • The Canvas command-line tool pulls and pushes components, and pushed components can still be opened in the browser editor.
  • Props and slots are the interface marketers use, so we recommend naming them for intent and keeping them few.
  • Pick one canonical place to edit each component, browser or local, so the next push holds no surprises.
  • Release 1.13.0 was listed on 05 Dec 2026, and stable releases fall under the security advisory policy.

‍

What are Drupal Canvas code components?

A code component is a piece of your own JavaScript and CSS that lives inside Drupal Canvas and can be managed in the Canvas interface. Once it exists, a marketer can drag it onto a page from the Library like any other component. The developer writes it once and the page builders reuse it.

On 05 Dec 2026 the Drupal.org project page listed version 1.13.0, released 18 November 2026, and said stable releases are covered by the security advisory policy. The notes for that release mention "more capable code components", so read the current release notes before you commit to a pattern.

The same release is listed as working with Drupal ^11.3, so a site on an older core version needs to move first. Our post on planning a Drupal 7 or 9 migration covers how to plan that route.

‍

How do front-end developers write a component with React?

You write a function component in JSX and export it. Drupal's documentation describes the browser editor as React/JSX, while the rendering layer is Preact with the React compatibility layer switched on. In practice that means familiar React habits carry over, but you should test anything that leans on a less common React feature.

Data comes in through props, and other components arrive through slots. Each prop can declare a type, say whether it is required and carry an example value. Prop and slot names are converted to camelCase before they reach your code, so the component receives a value such as firstName.

‍

Browser editor or local codebase: which one should you use?

Both routes produce the same kind of component. The difference is what each one lets you add around it.

Drupal's guidance is clear. Use the browser editor for changes contained in the component file and its CSS. Use a local codebase when you need new source files, static assets or package dependencies.

NeedBrowser editorLocal codebase
Edit one component and its CSSYesYes
Use imports already available to the componentYesYes
Add package dependenciesNoYes
Add new source files or static assetsNoYes
Use your own editor and source controlNoYes

‍

We recommend starting in the browser editor for a first component, because it removes setup as a variable. Move to a local codebase the day a second developer touches the same component. Source control is cheaper to adopt at that point than to retrofit after several people have edited the same file in a browser tab.

‍

What does the local workflow look like?

The local workflow has a short loop. You scaffold a project, pull what already exists, build, preview and push. Components that you push can still be opened later in the browser editor.

  1. Scaffold a project with npx @drupal-canvas/create@latest.
  2. Run npx canvas pull to download existing Canvas content into the project.
  3. Build and preview components locally. The scaffolded templates commonly include @drupal-canvas/workbench for preview and @drupal-canvas/eslint-config for validation.
  4. Run npx canvas push to build the assets, run the Tailwind CSS build and upload the component configuration.

‍

If your project does not use the default paths, a canvas.config.json file in the project root sets them. You only need to include the options you want to change.

{
  "componentDir": "src/code-components",
  "globalCssPath": "src/global.css",
  "sync": { "pages": true, "regions": true }
}

‍

The component directory can have any name, but it must sit inside the alias base directory. Place each component directly inside it rather than nesting components in grouping folders.

‍

How do you make a component safe for marketers to use?

A marketer will place your component on pages you never see, so the props are the real interface and the JSX is only the implementation. Our suggestion: give every prop a sensible example value and mark required inputs accurately. Keep the number of props small enough that a non-developer can predict what each one does.

Consider a hypothetical pricing card. A developer exposes a heading, a price line, a list of features and a button label, plus a slot for an optional badge.

The marketer can now build several plan pages from one component, and nobody touches the codebase. If the developer exposed a free-text field for raw styling, every page would drift. The component would stop being a design system and become a text box.

Accessibility belongs in the component, not in the page review. The W3C success criterion on name, role and value covers components generated by scripts. It says their name and role must be programmatically determined.

The criterion is aimed at authors who build their own components, and standard HTML controls already meet it when used to specification. So reach for a real button or link before you build a custom widget.

‍

What goes wrong in practice?

These are the failure modes we would design against from the first sprint. They come from how teams hand work between developers and page builders, and none is specific to one vendor's tooling.

  • Props that mirror the implementation. A prop named after a CSS value tells the marketer nothing about intent. Name it for the decision they are making.
  • Slots with no guidance. A slot that accepts anything invites a page that breaks the design. Say in the component's documentation what belongs inside.
  • Two sources of truth. If some developers edit in the browser and others push from a local codebase, the next pull or push can surprise somebody. Agree which one is canonical per component.
  • Accessibility left to the end. A custom control that never exposed its role or state is cheaper to fix before many pages use it.

‍

When does a decoupled approach make more sense?

Drupal documents two routes for decoupled front ends. The first uses code components with the CLI, so components written in the Canvas editor sync to an external project. The second is the Canvas External JavaScript Components module, canvas_extjs, which lets you write JavaScript in any framework, such as React or Vue, and deploy it independently.

The documented trade-off for the second route is losing the Canvas JavaScript editor interface. In exchange you get freedom in how the JavaScript is written, with support for client-side rendering and full server-side rendering.

We recommend it when the front-end team already owns a separate build pipeline. Stay with code components when marketers need to see and adjust the component in Canvas itself.

‍

Frequently Asked Questions
‍

1. Do code components need React?

Drupal's documentation describes the browser editor as React and JSX. Components render with Preact and the React compatibility layer enabled, so React-style code is the expected route.

2. Can I edit a component in the browser after pushing it from a local project?

Yes. Drupal's documentation says pushed components can still be opened and edited in the browser editor. New source files, static assets and package dependencies should still be added from the local codebase.

3. Which tools does the local workflow use?

The Canvas command-line tool provides pull and push. Scaffolded projects commonly include @drupal-canvas/workbench for local preview and @drupal-canvas/eslint-config for validating components.

4. Is Drupal Canvas stable enough to build on?

The Drupal.org project page listed version 1.13.0 on 05 Dec 2026 and stated that stable releases are covered by the security advisory policy. Check the release notes for the version you plan to install, because code component capabilities are still being extended.

5. Can I use a framework other than React with Drupal Canvas?

Drupal documents the Canvas External JavaScript Components module, canvas_extjs, which lets you write JavaScript in any framework, such as React or Vue. You deploy that code independently. The documented trade-off is that you lose the Canvas JavaScript editor interface.

‍

Sources

‍

CustomerIK works across product engineering.

If your front-end team is planning code components for Drupal Canvas and wants a second opinion on props and handover, let's talk.

‍

Preferences

Privacy is important to us, so you have the option of disabling certain types of storage that may not be necessary for the basic functioning of the website. Blocking categories may impact your experience on the website.

Accept all cookies
Accept all cookies

These items are required to enable basic website functionality.

Always active

These items are used to deliver advertising that is more relevant to you and your interests.

These items allow the website to remember choices you make (such as your user name, language, or the region you are in) and provide enhanced, more personal features.

These items help the website operator understand how its website performs, how visitors interact with the site, and whether there may be technical issues.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.