What this is for
Use this when you are building a website or app that embeds RuleCMS widgets and you want composer edits in the Development environment to show up on your site as soon as you save — without publishing to Staging or Production.
Staging and Production still use publish + published keys + the cache layer. Development uses a separate path that reads the live draft widget and its collections.
dev.… token and the widget's draft key (for example widget-…). You do not configure an API host — @rulecms/widget-react always calls https://rulecms.com for Development tokens.How it differs from Staging / Production
| Development | Staging / Production | |
|---|---|---|
| Content source | Live draft (composer tables) | Published snapshot |
| Publish required? | No | Yes |
| Token | Starts with dev. | No prefix |
publishedKey prop | Draft widget key (widget-…) | Published key ({envId}---widget-…) |
| API host (automatic) | https://rulecms.com | https://widget-cache.rulecms.com |
| Caching | Disabled (always fresh) | Cached until republish |
Prerequisites
- A RuleCMS team with a Development environment (created at signup).
@rulecms/widget-react22.11.0 or later in your app.- Your component libraries registered on the provider (same as published embeds — see Component Libraries).
Step 1 — Get a Development token
- In RuleCMS, open
…/app-project-env-tokens(or open Tokens from the Development environment home). - Select your app and the Development environment.
- Create or regenerate an enabled token. It must start with
dev.(for exampledev.AbCd…). - Store it as a secret in your app (env var / secrets manager).
dev. prefix. Regenerate them. Without the prefix, widget-react will treat the token as a published (Staging/Production) token and will not load drafts.Token management overview: Projects, Environments & Tokens.
Step 2 — Get the widget key
- Open the widget in the Development environment composer or widget manage page.
- Copy the widget key. It looks like
widget-9a31b6c8-….
Do not use a Staging/Production published key ({environmentId}---widget-…) with a dev. token.
Step 3 — Embed in your app
Pass the Development token and the draft widget key. Omit endpoint — the SDK chooses https://rulecms.com automatically.
import { RuleCMSWidgetProvider, RuleCMSWidget } from '@rulecms/widget-react';
import * as sourceComponents from '@rulecms/source-components-react';
// plus any team libraries you use…
const token = process.env.NEXT_PUBLIC_RULECMS_DEV_TOKEN; // starts with "dev."
const widgetKey = 'widget-…'; // draft key from Development
export function DevPreview() {
return (
<RuleCMSWidgetProvider
token={token}
libraries={{ default: sourceComponents }}
>
<RuleCMSWidget publishedKey={widgetKey} />
</RuleCMSWidgetProvider>
);
}The prop is still named publishedKey for API compatibility. In Development mode its value is the draft widget key.
For React Server Components, use RuleCMSWidgetServer or fetchRuleCMSWidget with the same token and key — routing is identical.
Step 4 — Edit and refresh
- Change the widget or a nested collection in the RuleCMS composer.
- Save.
- Refresh (or remount) your consuming page.
- You should see the new content immediately — no publish step.
Shared and embedded collections in Development are included automatically. Editing a collection used by the widget updates the next fetch the same way.
Going to Staging or Production
When you are ready for a stable, cacheable release:
- Promote or recreate content in Staging/Production and publish.
- Switch your app to a Staging/Production token (no
dev.prefix) and the widget's published key. widget-reactwill call the published API through widget-cache automatically.
Optional: call the HTTP API directly
You can skip the React SDK and call the draft endpoint yourself (for example from another framework):
GET https://rulecms.com/api/v1/c/dev/widget/get?token=dev.…&widgetKey=widget-…
- Response shape matches the published widget API.
- Responses are not cached (
Cache-Control: no-store). - The token must start with
dev.and belong to a non-Staging / non-Production environment.
Troubleshooting
| Symptom | Likely cause |
|---|---|
| 401 — token must start with "dev." | Regenerate the Development token so it includes the dev. prefix. Upgrade widget-react if you are on a version older than 22.11.0. |
| 404 Widget not found | Wrong key (using a published key), wrong environment, or the widget was deleted. Confirm the Development widget key. |
| Request goes to widget-cache instead of rulecms.com | Token does not start with dev., or an old endpoint prop is forcing the cache host — remove endpoint. |
| Changes in composer do not appear | Hard-refresh the consumer. Confirm you saved the draft and that the token's environment matches the widget's Development environment. |
| Staging/Production content looks wrong | Do not use a dev. token or draft key there. Use a published token + published key (see API Reference). |
Related docs
- HTML Custom Element Embed (any HTML site — no React host)
- Projects, Environments & Tokens
- API Reference (published path)
- Publishing
- Mount Your Own Components (Custom slot +
mounts) - Component Libraries
- Engineering: React derived state vs useEffect
- Engineering blog