Skip to content

Building ProcessReact Modules

ProcessReact (and its trait InteractWithReact) lets any ProcessWire Process module render the exact same React + Inertia application in two shell contexts without duplicating routes or components.

  • Embedded Admin Mode (shellMode: 'admin'): Default when opened from ProcessWire’s standard Admin menu (for example /admin/setup/my-module/). EmbeddedAdminPageResponse mounts the Inertia app cleanly inside AdminThemeUikit’s content region.
  • Full-Screen Workspace Mode (shellMode: 'workspace'): Activated automatically when opened with ?ws=1 or launched from Admin > Workspace. Wraps the view in SidebarShellLayout with ModuleSwitcher, Cmd/Ctrl+K Command Palette, and UserAccountMenu.
<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\React\Inertia\ProcessReact;
class ProcessCatalog extends ProcessReact
{
public function getModuleScriptAssets(): array
{
return [
$this->wire()->config->urls->siteModules . 'Catalog/dist/ProcessCatalog.js',
];
}
public function ___execute(): string
{
return (string) $this->inertiaRender('Catalog/Dashboard', [
'title' => $this->_('Catalog'),
]);
}
public function ___executeNavJSON(array $options = []): string|array
{
return $this->buildAdminNavJSON([
['url' => '', 'label' => $this->_('Overview'), 'icon' => 'layout-grid'],
['url' => 'items/', 'label' => $this->_('Items'), 'icon' => 'list'],
], $options);
}
}

Zero-Cost Lazy Capability Registration (reactCapabilities)

Section titled “Zero-Cost Lazy Capability Registration (reactCapabilities)”

Never set 'autoload' => true on a downstream module just to register workspaces, widgets, providers, or icon packs. Instead, keep 'autoload' => false and declare 'reactCapabilities' in your module’s getModuleInfo():

<?php
declare(strict_types=1);
namespace ProcessWire;
$info = [
'title' => 'Catalog',
'version' => 1,
'autoload' => false,
'requires' => ['PHP>=8.4', 'ProcessWire>=3.0.271', 'React'],
'reactCapabilities' => [
'workspace',
'icons',
'commandSearch',
'providers',
'relations',
'linkResolvers',
'media',
'viewportModes',
],
];

React reads the cached module info manifest and wakes your module only when a request actually needs one of those capabilities.

All 15 Hookable Methods & Deferred Registration Helpers

Section titled “All 15 Hookable Methods & Deferred Registration Helpers”

Inside your module’s __construct() or init(), register callbacks using React::defer*Registration() or hook the corresponding ___* method directly:

Hook Arguments & Return Timing What It Does
React::registerWorkspaces (WorkspaceRegistry $registry): void After Registers WorkspaceDefinition modules in the full-screen Workspace switcher (React::deferModuleRegistration()).
React::registerWidgets (WorkspaceWidgetRegistry $registry): void After Registers Bento dashboard WorkspaceWidgetDefinition cards on the Workspace Home screen.
React::registerCommandSearch (CommandSearchRegistry $registry): void After Registers Cmd/Ctrl+K live Command Palette search providers (React::deferCommandSearchRegistration()).
React::registerProviders (ProviderRegistry $registry): void After Registers custom ReactDataProviderInterface factories (React::deferProviderRegistration()).
React::registerRelationResources (RelationResourceRegistry $registry): void After Registers custom RelationResourceInterface sources for relation pickers.
React::registerLinkResolvers (): void After Registers custom target resolvers for InputfieldReactLink.
React::registerMediaHosts (MediaGateway $gateway): void After Registers custom media host adapters in MediaGateway.
React::registerMediaLibrary (MediaGateway $gateway): void After Registers shared media library browser adapters in MediaGateway.
React::registerViewportModes (): void After Registers custom viewport layout modes (React::deferViewportModeRegistration()).
React::translations (): array After Returns localized UI string maps for the shared React runtime.
InputfieldTiptap::registerMiniBlocks (array $blocks): array After Appends or filters custom rich-text mini-block definitions inside InputfieldTiptap.
InputfieldTiptap::translations (): array After Returns localized toolbar and dialog labels for InputfieldTiptap.
MarkupReactViewport::render (string|array|Closure|PageArray|ReactDataProviderInterface $provider = '', array $props = []): string Before / After Renders a table, card, or list viewport widget with its serialized props.
PageLinkFilesManager::path (): string After Resolves the disk storage path for InputfieldReactLink file uploads.
PageLinkFilesManager::url (): string After Resolves the public URL prefix for InputfieldReactLink file uploads.

Register a Custom Dashboard Widget & Customize Runtime Labels

Section titled “Register a Custom Dashboard Widget & Customize Runtime Labels”
site/ready.php
<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\React\Workspace\WorkspaceWidgetDefinition;
use Totoglu\React\Workspace\WorkspaceWidgetRegistry;
$wire->addHookAfter('React::registerWidgets', function (HookEvent $event): void {
/** @var WorkspaceWidgetRegistry $registry */
$registry = $event->arguments(0);
$registry->register(new WorkspaceWidgetDefinition(
key: 'aegean.fleet-status',
title: 'Fleet Readiness',
description: 'Live charter availability snapshot.',
moduleKey: 'charter',
));
});
$wire->addHookAfter('React::translations', function (HookEvent $event): void {
$strings = (array) $event->return;
$strings['workspace.searchPlaceholder'] = 'Search yachts, bookings, or pages...';
$event->return = $strings;
});

Broadcasting Save Events & Uninstall Cleanup

Section titled “Broadcasting Save Events & Uninstall Cleanup”
  • Co-editing presence: Call React::instance($this)->notifyResourceSaved($resourceKey, $recordId) after saving a record so co-editors see a live stale-form banner via /_react/presence.
  • Clean uninstall: Inside your module’s ___uninstall(), call React::forgetSharedWorkspace(), React::forgetSharedWidget(), React::forgetSharedViewportMode(), and React::forgetDeferredRegistrations($this->className()) so WorkspacePreferenceStore prunes stale user preferences automatically.

Next steps