From aaa49ddecee49ad09704d7f8dbdd32ce04463512 Mon Sep 17 00:00:00 2001 From: Paulo Carvalho Date: Fri, 1 May 2026 23:17:11 +0100 Subject: [PATCH 1/5] feat: add inertia frontend config slots --- packages/inertia/config/inertia.php | 2 ++ .../src/Frontend/InertiaFrontendInterface.php | 10 ++++++++++ packages/inertia/src/Inertia.php | 1 + packages/inertia/tests/InertiaTest.php | 19 +++++++++++++++++++ packages/inertia/tests/ModuleTest.php | 10 ++++++++++ 5 files changed, 42 insertions(+) create mode 100644 packages/inertia/src/Frontend/InertiaFrontendInterface.php diff --git a/packages/inertia/config/inertia.php b/packages/inertia/config/inertia.php index a79781b5..7f35fb60 100644 --- a/packages/inertia/config/inertia.php +++ b/packages/inertia/config/inertia.php @@ -4,8 +4,10 @@ return [ 'version' => null, + 'assetEntry' => null, 'ssr' => [ 'enabled' => env('INERTIA_SSR_ENABLED', false), 'url' => env('INERTIA_SSR_URL', 'http://localhost:13714'), + 'bundle' => null, ], ]; diff --git a/packages/inertia/src/Frontend/InertiaFrontendInterface.php b/packages/inertia/src/Frontend/InertiaFrontendInterface.php new file mode 100644 index 00000000..e76246c0 --- /dev/null +++ b/packages/inertia/src/Frontend/InertiaFrontendInterface.php @@ -0,0 +1,10 @@ +nullableScalarConfig('inertia.assetEntry'); $props = $this->resolveProps($props, $request, $component); $page = [ diff --git a/packages/inertia/tests/InertiaTest.php b/packages/inertia/tests/InertiaTest.php index f96dcf8d..66984583 100644 --- a/packages/inertia/tests/InertiaTest.php +++ b/packages/inertia/tests/InertiaTest.php @@ -21,8 +21,10 @@ function createInertia(array $config = [], array $viteConfig = []): Inertia { $mergedConfig = new FakeConfigRepository(array_merge([ 'inertia.version' => '1.0', + 'inertia.assetEntry' => null, 'inertia.ssr.enabled' => false, 'inertia.ssr.url' => 'http://localhost:13714', + 'inertia.ssr.bundle' => null, 'vite.entry' => 'app/web/resources/js/app.js', 'vite.buildDirectory' => 'build', 'vite.manifestFilename' => '.vite/manifest.json', @@ -104,6 +106,23 @@ function createInertia(array $config = [], array $viteConfig = []): Inertia expect($response->body())->not->toContain('app/web/resources/js/app.js'); }); +test('inertia html defaults to the configured inertia asset entry when present', function () { + $inertia = createInertia([ + 'inertia.assetEntry' => 'app/react-web/resources/js/app.jsx', + ], [ + 'entry' => 'app/web/resources/js/app.js', + 'devServerUrl' => 'http://localhost:5173', + 'devServerStylesheets' => [], + 'useDevServer' => true, + ]); + $request = new Request(); + + $response = $inertia->render($request, 'ReactHome'); + + expect($response->body())->toContain('http://localhost:5173/app/react-web/resources/js/app.jsx'); + expect($response->body())->not->toContain('app/web/resources/js/app.js'); +}); + test('inertia merges shared data with page props', function () { $inertia = createInertia(); $inertia->share('flash', ['message' => 'Hello']); diff --git a/packages/inertia/tests/ModuleTest.php b/packages/inertia/tests/ModuleTest.php index f05f71e8..c6490e48 100644 --- a/packages/inertia/tests/ModuleTest.php +++ b/packages/inertia/tests/ModuleTest.php @@ -24,3 +24,13 @@ expect($module)->not->toHaveKey('enabled') ->and($module)->not->toHaveKey('sequence'); }); + +test('inertia config declares frontend overlay slots', function () { + $config = require dirname(__DIR__).'/config/inertia.php'; + + expect($config['version'])->toBeNull() + ->and($config['assetEntry'])->toBeNull() + ->and($config['ssr']['enabled'])->toBeFalse() + ->and($config['ssr']['url'])->toBe('http://localhost:13714') + ->and($config['ssr']['bundle'])->toBeNull(); +}); From 0591d3cb723ce2667b842db4f358070d55dcf9c8 Mon Sep 17 00:00:00 2001 From: Paulo Carvalho Date: Sat, 25 Apr 2026 12:19:31 +0100 Subject: [PATCH 2/5] Add marko inertia react package --- .github/ISSUE_TEMPLATE/bug_report.yml | 1 + .github/ISSUE_TEMPLATE/feature_request.yml | 1 + composer.json | 6 ++ packages/inertia-react/.gitattributes | 5 ++ packages/inertia-react/LICENSE | 20 +++++++ packages/inertia-react/README.md | 59 +++++++++++++++++++ packages/inertia-react/composer.json | 28 +++++++++ .../inertia-react/config/inertia-react.php | 14 +++++ packages/inertia-react/module.php | 10 ++++ .../inertia-react/tests/InertiaReactTest.php | 19 ++++++ 10 files changed, 163 insertions(+) create mode 100644 packages/inertia-react/.gitattributes create mode 100644 packages/inertia-react/LICENSE create mode 100644 packages/inertia-react/README.md create mode 100644 packages/inertia-react/composer.json create mode 100644 packages/inertia-react/config/inertia-react.php create mode 100644 packages/inertia-react/module.php create mode 100644 packages/inertia-react/tests/InertiaReactTest.php diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index e211e7b1..aab8fb18 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -82,6 +82,7 @@ body: - http - http-guzzle - inertia + - inertia-react - layout - log - log-file diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index 35f62029..9daf1825 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -70,6 +70,7 @@ body: - http - http-guzzle - inertia + - inertia-react - layout - log - log-file diff --git a/composer.json b/composer.json index 78950d85..d10c1eb2 100644 --- a/composer.json +++ b/composer.json @@ -144,6 +144,10 @@ "type": "path", "url": "packages/inertia" }, + { + "type": "path", + "url": "packages/inertia-react" + }, { "type": "path", "url": "packages/layout" @@ -341,6 +345,7 @@ "marko/hashing": "self.version", "marko/health": "self.version", "marko/inertia": "self.version", + "marko/inertia-react": "self.version", "marko/http": "self.version", "marko/layout": "self.version", "marko/http-guzzle": "self.version", @@ -447,6 +452,7 @@ "Marko\\Hashing\\Tests\\": "packages/hashing/tests/", "Marko\\Health\\Tests\\": "packages/health/tests/", "Marko\\Inertia\\Tests\\": "packages/inertia/tests/", + "Marko\\InertiaReact\\Tests\\": "packages/inertia-react/tests/", "Marko\\Http\\Tests\\": "packages/http/tests/", "Marko\\Http\\Guzzle\\Tests\\": "packages/http-guzzle/tests/", "Marko\\Layout\\Tests\\": "packages/layout/tests/", diff --git a/packages/inertia-react/.gitattributes b/packages/inertia-react/.gitattributes new file mode 100644 index 00000000..e5736f06 --- /dev/null +++ b/packages/inertia-react/.gitattributes @@ -0,0 +1,5 @@ +/tests export-ignore +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/phpunit.xml.dist export-ignore diff --git a/packages/inertia-react/LICENSE b/packages/inertia-react/LICENSE new file mode 100644 index 00000000..99a76f97 --- /dev/null +++ b/packages/inertia-react/LICENSE @@ -0,0 +1,20 @@ +MIT License + +Copyright (c) Devtomic LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/inertia-react/README.md b/packages/inertia-react/README.md new file mode 100644 index 00000000..ab2da216 --- /dev/null +++ b/packages/inertia-react/README.md @@ -0,0 +1,59 @@ +# Marko Inertia React + +Configuration defaults for React apps built with `marko/inertia` and `marko/vite`. + +## Install + +```bash +composer require marko/inertia marko/inertia-react marko/vite +npm install @inertiajs/react@^3.0 react@^19.0 react-dom@^19.0 @vitejs/plugin-react@^6.0 vite@^8.0 +``` + +## Files + +Create the client entry at `app/react-web/resources/js/app.jsx`: + +```jsx +import { createInertiaApp } from '@inertiajs/react'; +import { createRoot } from 'react-dom/client'; + +createInertiaApp({ + resolve: (name) => { + const pages = import.meta.glob('./Pages/**/*.jsx', { eager: true }); + return pages[`./Pages/${name}.jsx`]; + }, + setup({ el, App, props }) { + createRoot(el).render(); + }, +}); +``` + +Create the SSR entry at `app/react-web/resources/js/ssr.jsx`: + +```jsx +import { createInertiaApp } from '@inertiajs/react'; +import createServer from '@inertiajs/react/server'; +import ReactDOMServer from 'react-dom/server'; + +createServer((page) => + createInertiaApp({ + page, + render: ReactDOMServer.renderToString, + resolve: (name) => { + const pages = import.meta.glob('./Pages/**/*.jsx', { eager: true }); + return pages[`./Pages/${name}.jsx`]; + }, + setup: ({ App, props }) => , + }), +); +``` + +## Configuration + +The package exposes: + +- `clientEntry`: `app/react-web/resources/js/app.jsx` +- `ssrEntry`: `app/react-web/resources/js/ssr.jsx` +- `ssrBundle`: `bootstrap/ssr/react/ssr.js` + +Override them with `INERTIA_REACT_CLIENT_ENTRY`, `INERTIA_REACT_SSR_ENTRY`, and `INERTIA_REACT_SSR_BUNDLE`. diff --git a/packages/inertia-react/composer.json b/packages/inertia-react/composer.json new file mode 100644 index 00000000..490155b9 --- /dev/null +++ b/packages/inertia-react/composer.json @@ -0,0 +1,28 @@ +{ + "name": "marko/inertia-react", + "type": "marko-module", + "description": "React companion for marko/inertia — configuration for React client and SSR entries", + "license": "MIT", + "require": { + "php": "^8.5", + "marko/core": "self.version", + "marko/env": "self.version", + "marko/inertia": "self.version", + "marko/vite": "self.version" + }, + "autoload": { + "psr-4": { + "Marko\\InertiaReact\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Marko\\InertiaReact\\Tests\\": "tests/" + } + }, + "extra": { + "marko": { + "module": true + } + } +} diff --git a/packages/inertia-react/config/inertia-react.php b/packages/inertia-react/config/inertia-react.php new file mode 100644 index 00000000..8137bbd2 --- /dev/null +++ b/packages/inertia-react/config/inertia-react.php @@ -0,0 +1,14 @@ + env('INERTIA_REACT_CLIENT_ENTRY', 'app/react-web/resources/js/app.jsx'), + 'ssrEntry' => env('INERTIA_REACT_SSR_ENTRY', 'app/react-web/resources/js/ssr.jsx'), + 'ssrBundle' => env('INERTIA_REACT_SSR_BUNDLE', $basePath.'/bootstrap/ssr/react/ssr.js'), +]; diff --git a/packages/inertia-react/module.php b/packages/inertia-react/module.php new file mode 100644 index 00000000..12a179a2 --- /dev/null +++ b/packages/inertia-react/module.php @@ -0,0 +1,10 @@ + true, + 'sequence' => [ + 'after' => ['marko/inertia', 'marko/vite'], + ], +]; diff --git a/packages/inertia-react/tests/InertiaReactTest.php b/packages/inertia-react/tests/InertiaReactTest.php new file mode 100644 index 00000000..b5c5d3bb --- /dev/null +++ b/packages/inertia-react/tests/InertiaReactTest.php @@ -0,0 +1,19 @@ +toBe('app/react-web/resources/js/app.jsx'); + expect($config['ssrEntry'])->toBe('app/react-web/resources/js/ssr.jsx'); + expect($config['ssrBundle'])->toEndWith('/bootstrap/ssr/react/ssr.js'); +}); + +test('inertia-react module depends on inertia and vite', function () { + $module = require dirname(__DIR__).'/module.php'; + + expect($module['enabled'])->toBeTrue(); + expect($module['sequence']['after'])->toContain('marko/inertia'); + expect($module['sequence']['after'])->toContain('marko/vite'); +}); From a038fce85411b75dfc56638dd8a2759b19703f5f Mon Sep 17 00:00:00 2001 From: Paulo Carvalho Date: Fri, 1 May 2026 20:32:00 +0100 Subject: [PATCH 3/5] refactor: align marko/inertia-react with package conventions and add docs page --- .../content/docs/packages/inertia-react.md | 109 ++++++++++++++++++ packages/inertia-react/.gitattributes | 2 +- packages/inertia-react/README.md | 78 +++++-------- packages/inertia-react/composer.json | 45 ++++---- .../inertia-react/config/inertia-react.php | 7 +- packages/inertia-react/module.php | 10 -- .../inertia-react/tests/InertiaReactTest.php | 15 ++- 7 files changed, 168 insertions(+), 98 deletions(-) create mode 100644 docs/src/content/docs/packages/inertia-react.md delete mode 100644 packages/inertia-react/module.php diff --git a/docs/src/content/docs/packages/inertia-react.md b/docs/src/content/docs/packages/inertia-react.md new file mode 100644 index 00000000..48f33b0c --- /dev/null +++ b/docs/src/content/docs/packages/inertia-react.md @@ -0,0 +1,109 @@ +--- +title: marko/inertia-react +description: React companion for marko/inertia - configuration defaults for React client and SSR entries. +--- + +React companion for [`marko/inertia`](/docs/packages/inertia/) and [`marko/vite`](/docs/packages/vite/). It ships Marko configuration defaults for React client and SSR entrypoints while leaving the JavaScript application code in your project. + +## Installation + +```bash +composer require marko/inertia-react +``` + +Install the matching frontend dependencies in your app: + +```bash +npm install @inertiajs/react@^3.0 react@^19.0 react-dom@^19.0 @vitejs/plugin-react@^6.0 vite@^8.0 +``` + +## Configuration + +Configure via `config/inertia-react.php`: + +```php title="config/inertia-react.php" +return [ + 'clientEntry' => env('INERTIA_REACT_CLIENT_ENTRY', 'app/react-web/resources/js/app.jsx'), + 'ssrEntry' => env('INERTIA_REACT_SSR_ENTRY', 'app/react-web/resources/js/ssr.jsx'), + 'ssrBundle' => env('INERTIA_REACT_SSR_BUNDLE', 'bootstrap/ssr/react/ssr.js'), +]; +``` + +| Key | Purpose | +| --- | --- | +| `clientEntry` | Vite entry used by browser-rendered Inertia responses. | +| `ssrEntry` | Vite entry used to build the React SSR server bundle. | +| `ssrBundle` | Relative path to the built SSR bundle loaded by your SSR runner. | + +## Usage + +Use the configured client entry when rendering React-backed Inertia pages: + +```php +use Marko\Inertia\Inertia; +use Marko\Routing\Http\Request; +use Marko\Routing\Http\Response; + +class DashboardController +{ + public function __construct( + private readonly Inertia $inertia, + ) {} + + public function index(Request $request): Response + { + return $this->inertia->render( + request: $request, + component: 'Dashboard', + assetEntry: 'app/react-web/resources/js/app.jsx', + ); + } +} +``` + +Create the client entry at `app/react-web/resources/js/app.jsx`: + +```jsx title="app/react-web/resources/js/app.jsx" +import { createInertiaApp } from '@inertiajs/react'; +import { createRoot } from 'react-dom/client'; + +createInertiaApp({ + resolve: (name) => { + const pages = import.meta.glob('./Pages/**/*.jsx', { eager: true }); + return pages[`./Pages/${name}.jsx`]; + }, + setup({ el, App, props }) { + createRoot(el).render(); + }, +}); +``` + +Create the SSR entry at `app/react-web/resources/js/ssr.jsx`: + +```jsx title="app/react-web/resources/js/ssr.jsx" +import { createInertiaApp } from '@inertiajs/react'; +import createServer from '@inertiajs/react/server'; +import ReactDOMServer from 'react-dom/server'; + +createServer((page) => + createInertiaApp({ + page, + render: ReactDOMServer.renderToString, + resolve: (name) => { + const pages = import.meta.glob('./Pages/**/*.jsx', { eager: true }); + return pages[`./Pages/${name}.jsx`]; + }, + setup: ({ App, props }) => , + }), +); +``` + +## API Reference + +This package is configuration-only. It does not add PHP services or bindings; `module.php` is intentionally omitted because Marko can discover the package through Composer metadata and load its `config/` directory without explicit module options. + +## Related Packages + +- [`marko/inertia`](/docs/packages/inertia/) - renders Inertia responses and handles SSR fallback +- [`marko/vite`](/docs/packages/vite/) - resolves the configured React Vite entry +- [`marko/env`](/docs/packages/env/) - provides the `env()` helper used in `config/inertia-react.php` diff --git a/packages/inertia-react/.gitattributes b/packages/inertia-react/.gitattributes index e5736f06..aa78278f 100644 --- a/packages/inertia-react/.gitattributes +++ b/packages/inertia-react/.gitattributes @@ -1,5 +1,5 @@ /tests export-ignore -/.github export-ignore +/.github export-ignore /.gitattributes export-ignore /.gitignore export-ignore /phpunit.xml.dist export-ignore diff --git a/packages/inertia-react/README.md b/packages/inertia-react/README.md index ab2da216..e463617a 100644 --- a/packages/inertia-react/README.md +++ b/packages/inertia-react/README.md @@ -1,59 +1,37 @@ -# Marko Inertia React +# marko/inertia-react -Configuration defaults for React apps built with `marko/inertia` and `marko/vite`. +React companion for `marko/inertia` - configuration for React client and SSR entries. -## Install +## Installation ```bash -composer require marko/inertia marko/inertia-react marko/vite -npm install @inertiajs/react@^3.0 react@^19.0 react-dom@^19.0 @vitejs/plugin-react@^6.0 vite@^8.0 +composer require marko/inertia-react ``` -## Files - -Create the client entry at `app/react-web/resources/js/app.jsx`: - -```jsx -import { createInertiaApp } from '@inertiajs/react'; -import { createRoot } from 'react-dom/client'; - -createInertiaApp({ - resolve: (name) => { - const pages = import.meta.glob('./Pages/**/*.jsx', { eager: true }); - return pages[`./Pages/${name}.jsx`]; - }, - setup({ el, App, props }) { - createRoot(el).render(); - }, -}); +## Quick Example + +```php +use Marko\Inertia\Inertia; +use Marko\Routing\Http\Request; +use Marko\Routing\Http\Response; + +class DashboardController +{ + public function __construct( + private readonly Inertia $inertia, + ) {} + + public function index(Request $request): Response + { + return $this->inertia->render( + request: $request, + component: 'Dashboard', + assetEntry: 'app/react-web/resources/js/app.jsx', + ); + } +} ``` -Create the SSR entry at `app/react-web/resources/js/ssr.jsx`: - -```jsx -import { createInertiaApp } from '@inertiajs/react'; -import createServer from '@inertiajs/react/server'; -import ReactDOMServer from 'react-dom/server'; - -createServer((page) => - createInertiaApp({ - page, - render: ReactDOMServer.renderToString, - resolve: (name) => { - const pages = import.meta.glob('./Pages/**/*.jsx', { eager: true }); - return pages[`./Pages/${name}.jsx`]; - }, - setup: ({ App, props }) => , - }), -); -``` - -## Configuration - -The package exposes: - -- `clientEntry`: `app/react-web/resources/js/app.jsx` -- `ssrEntry`: `app/react-web/resources/js/ssr.jsx` -- `ssrBundle`: `bootstrap/ssr/react/ssr.js` +## Documentation -Override them with `INERTIA_REACT_CLIENT_ENTRY`, `INERTIA_REACT_SSR_ENTRY`, and `INERTIA_REACT_SSR_BUNDLE`. +Full usage, API reference, and examples: [marko/inertia-react](https://marko.build/docs/packages/inertia-react/) diff --git a/packages/inertia-react/composer.json b/packages/inertia-react/composer.json index 490155b9..fde0aac5 100644 --- a/packages/inertia-react/composer.json +++ b/packages/inertia-react/composer.json @@ -1,28 +1,23 @@ { - "name": "marko/inertia-react", - "type": "marko-module", - "description": "React companion for marko/inertia — configuration for React client and SSR entries", - "license": "MIT", - "require": { - "php": "^8.5", - "marko/core": "self.version", - "marko/env": "self.version", - "marko/inertia": "self.version", - "marko/vite": "self.version" - }, - "autoload": { - "psr-4": { - "Marko\\InertiaReact\\": "src/" + "name": "marko/inertia-react", + "description": "React companion for marko/inertia - configuration for React client and SSR entries", + "license": "MIT", + "type": "marko-module", + "require": { + "php": "^8.5", + "marko/core": "self.version", + "marko/env": "self.version", + "marko/inertia": "self.version", + "marko/vite": "self.version" + }, + "autoload-dev": { + "psr-4": { + "Marko\\InertiaReact\\Tests\\": "tests/" + } + }, + "extra": { + "marko": { + "module": true + } } - }, - "autoload-dev": { - "psr-4": { - "Marko\\InertiaReact\\Tests\\": "tests/" - } - }, - "extra": { - "marko": { - "module": true - } - } } diff --git a/packages/inertia-react/config/inertia-react.php b/packages/inertia-react/config/inertia-react.php index 8137bbd2..f64c0ac7 100644 --- a/packages/inertia-react/config/inertia-react.php +++ b/packages/inertia-react/config/inertia-react.php @@ -2,13 +2,8 @@ declare(strict_types=1); -$documentRoot = $_SERVER['DOCUMENT_ROOT'] ?? null; -$basePath = is_string($documentRoot) && $documentRoot !== '' - ? dirname($documentRoot) - : (getcwd() ?: ''); - return [ 'clientEntry' => env('INERTIA_REACT_CLIENT_ENTRY', 'app/react-web/resources/js/app.jsx'), 'ssrEntry' => env('INERTIA_REACT_SSR_ENTRY', 'app/react-web/resources/js/ssr.jsx'), - 'ssrBundle' => env('INERTIA_REACT_SSR_BUNDLE', $basePath.'/bootstrap/ssr/react/ssr.js'), + 'ssrBundle' => env('INERTIA_REACT_SSR_BUNDLE', 'bootstrap/ssr/react/ssr.js'), ]; diff --git a/packages/inertia-react/module.php b/packages/inertia-react/module.php deleted file mode 100644 index 12a179a2..00000000 --- a/packages/inertia-react/module.php +++ /dev/null @@ -1,10 +0,0 @@ - true, - 'sequence' => [ - 'after' => ['marko/inertia', 'marko/vite'], - ], -]; diff --git a/packages/inertia-react/tests/InertiaReactTest.php b/packages/inertia-react/tests/InertiaReactTest.php index b5c5d3bb..00fd0b00 100644 --- a/packages/inertia-react/tests/InertiaReactTest.php +++ b/packages/inertia-react/tests/InertiaReactTest.php @@ -7,13 +7,16 @@ expect($config['clientEntry'])->toBe('app/react-web/resources/js/app.jsx'); expect($config['ssrEntry'])->toBe('app/react-web/resources/js/ssr.jsx'); - expect($config['ssrBundle'])->toEndWith('/bootstrap/ssr/react/ssr.js'); + expect($config['ssrBundle'])->toBe('bootstrap/ssr/react/ssr.js'); }); -test('inertia-react module depends on inertia and vite', function () { - $module = require dirname(__DIR__).'/module.php'; +test('inertia-react is a config-only marko module', function () { + $composer = json_decode( + file_get_contents(dirname(__DIR__).'/composer.json'), + true, + flags: JSON_THROW_ON_ERROR, + ); - expect($module['enabled'])->toBeTrue(); - expect($module['sequence']['after'])->toContain('marko/inertia'); - expect($module['sequence']['after'])->toContain('marko/vite'); + expect(file_exists(dirname(__DIR__).'/module.php'))->toBeFalse() + ->and($composer['extra']['marko']['module'])->toBeTrue(); }); From 45a6e3f096bc4b461bc1e9c5f9e1d55ec82d8319 Mon Sep 17 00:00:00 2001 From: Paulo Carvalho Date: Fri, 1 May 2026 23:19:08 +0100 Subject: [PATCH 4/5] refactor: wire inertia react companion through parent config --- .../content/docs/packages/inertia-react.md | 31 ++++++++++--------- packages/inertia-react/README.md | 3 +- packages/inertia-react/composer.json | 7 ++++- .../inertia-react/config/inertia-react.php | 9 ------ packages/inertia-react/config/inertia.php | 10 ++++++ packages/inertia-react/module.php | 12 +++++++ .../src/ReactInertiaFrontend.php | 15 +++++++++ .../inertia-react/tests/InertiaReactTest.php | 31 ++++++++++++++----- 8 files changed, 83 insertions(+), 35 deletions(-) delete mode 100644 packages/inertia-react/config/inertia-react.php create mode 100644 packages/inertia-react/config/inertia.php create mode 100644 packages/inertia-react/module.php create mode 100644 packages/inertia-react/src/ReactInertiaFrontend.php diff --git a/docs/src/content/docs/packages/inertia-react.md b/docs/src/content/docs/packages/inertia-react.md index 48f33b0c..46c57840 100644 --- a/docs/src/content/docs/packages/inertia-react.md +++ b/docs/src/content/docs/packages/inertia-react.md @@ -1,9 +1,9 @@ --- title: marko/inertia-react -description: React companion for marko/inertia - configuration defaults for React client and SSR entries. +description: React companion for marko/inertia - configuration defaults and a frontend marker binding for React. --- -React companion for [`marko/inertia`](/docs/packages/inertia/) and [`marko/vite`](/docs/packages/vite/). It ships Marko configuration defaults for React client and SSR entrypoints while leaving the JavaScript application code in your project. +React companion for [`marko/inertia`](/docs/packages/inertia/) and [`marko/vite`](/docs/packages/vite/). It overlays the parent Inertia configuration with React defaults and registers a frontend marker binding so installing multiple Inertia frontend companions fails loudly. ## Installation @@ -14,30 +14,32 @@ composer require marko/inertia-react Install the matching frontend dependencies in your app: ```bash -npm install @inertiajs/react@^3.0 react@^19.0 react-dom@^19.0 @vitejs/plugin-react@^6.0 vite@^8.0 +npm install @inertiajs/react react react-dom @vitejs/plugin-react vite ``` +Refer to the Inertia.js docs for currently supported versions of each frontend adapter. + ## Configuration -Configure via `config/inertia-react.php`: +This package contributes defaults to the parent `config/inertia.php` namespace: -```php title="config/inertia-react.php" +```php title="packages/inertia-react/config/inertia.php" return [ - 'clientEntry' => env('INERTIA_REACT_CLIENT_ENTRY', 'app/react-web/resources/js/app.jsx'), - 'ssrEntry' => env('INERTIA_REACT_SSR_ENTRY', 'app/react-web/resources/js/ssr.jsx'), - 'ssrBundle' => env('INERTIA_REACT_SSR_BUNDLE', 'bootstrap/ssr/react/ssr.js'), + 'assetEntry' => env('INERTIA_REACT_CLIENT_ENTRY', 'app/react-web/resources/js/app.jsx'), + 'ssr' => [ + 'bundle' => env('INERTIA_REACT_SSR_BUNDLE', 'bootstrap/ssr/react/ssr.js'), + ], ]; ``` | Key | Purpose | | --- | --- | -| `clientEntry` | Vite entry used by browser-rendered Inertia responses. | -| `ssrEntry` | Vite entry used to build the React SSR server bundle. | -| `ssrBundle` | Relative path to the built SSR bundle loaded by your SSR runner. | +| `assetEntry` | Vite entry used by browser-rendered Inertia responses. | +| `ssr.bundle` | Relative path to the built SSR bundle loaded by your SSR runner. | ## Usage -Use the configured client entry when rendering React-backed Inertia pages: +Render React-backed Inertia pages without passing an asset entry; `marko/inertia` reads it from configuration: ```php use Marko\Inertia\Inertia; @@ -55,7 +57,6 @@ class DashboardController return $this->inertia->render( request: $request, component: 'Dashboard', - assetEntry: 'app/react-web/resources/js/app.jsx', ); } } @@ -100,10 +101,10 @@ createServer((page) => ## API Reference -This package is configuration-only. It does not add PHP services or bindings; `module.php` is intentionally omitted because Marko can discover the package through Composer metadata and load its `config/` directory without explicit module options. +This package registers `Marko\Inertia\Frontend\InertiaFrontendInterface` to a React marker implementation. Installing more than one Inertia frontend companion produces the same binding conflict protection used by Marko driver siblings. ## Related Packages - [`marko/inertia`](/docs/packages/inertia/) - renders Inertia responses and handles SSR fallback - [`marko/vite`](/docs/packages/vite/) - resolves the configured React Vite entry -- [`marko/env`](/docs/packages/env/) - provides the `env()` helper used in `config/inertia-react.php` +- [`marko/env`](/docs/packages/env/) - provides the `env()` helper used in `config/inertia.php` diff --git a/packages/inertia-react/README.md b/packages/inertia-react/README.md index e463617a..6d4845f2 100644 --- a/packages/inertia-react/README.md +++ b/packages/inertia-react/README.md @@ -1,6 +1,6 @@ # marko/inertia-react -React companion for `marko/inertia` - configuration for React client and SSR entries. +React companion for `marko/inertia` - configuration defaults and a frontend marker binding for React. ## Installation @@ -26,7 +26,6 @@ class DashboardController return $this->inertia->render( request: $request, component: 'Dashboard', - assetEntry: 'app/react-web/resources/js/app.jsx', ); } } diff --git a/packages/inertia-react/composer.json b/packages/inertia-react/composer.json index fde0aac5..0a098395 100644 --- a/packages/inertia-react/composer.json +++ b/packages/inertia-react/composer.json @@ -1,6 +1,6 @@ { "name": "marko/inertia-react", - "description": "React companion for marko/inertia - configuration for React client and SSR entries", + "description": "React companion for marko/inertia - configuration and frontend marker binding", "license": "MIT", "type": "marko-module", "require": { @@ -10,6 +10,11 @@ "marko/inertia": "self.version", "marko/vite": "self.version" }, + "autoload": { + "psr-4": { + "Marko\\Inertia\\React\\": "src/" + } + }, "autoload-dev": { "psr-4": { "Marko\\InertiaReact\\Tests\\": "tests/" diff --git a/packages/inertia-react/config/inertia-react.php b/packages/inertia-react/config/inertia-react.php deleted file mode 100644 index f64c0ac7..00000000 --- a/packages/inertia-react/config/inertia-react.php +++ /dev/null @@ -1,9 +0,0 @@ - env('INERTIA_REACT_CLIENT_ENTRY', 'app/react-web/resources/js/app.jsx'), - 'ssrEntry' => env('INERTIA_REACT_SSR_ENTRY', 'app/react-web/resources/js/ssr.jsx'), - 'ssrBundle' => env('INERTIA_REACT_SSR_BUNDLE', 'bootstrap/ssr/react/ssr.js'), -]; diff --git a/packages/inertia-react/config/inertia.php b/packages/inertia-react/config/inertia.php new file mode 100644 index 00000000..225509b5 --- /dev/null +++ b/packages/inertia-react/config/inertia.php @@ -0,0 +1,10 @@ + env('INERTIA_REACT_CLIENT_ENTRY', 'app/react-web/resources/js/app.jsx'), + 'ssr' => [ + 'bundle' => env('INERTIA_REACT_SSR_BUNDLE', 'bootstrap/ssr/react/ssr.js'), + ], +]; diff --git a/packages/inertia-react/module.php b/packages/inertia-react/module.php new file mode 100644 index 00000000..797abbd1 --- /dev/null +++ b/packages/inertia-react/module.php @@ -0,0 +1,12 @@ + [ + InertiaFrontendInterface::class => ReactInertiaFrontend::class, + ], +]; diff --git a/packages/inertia-react/src/ReactInertiaFrontend.php b/packages/inertia-react/src/ReactInertiaFrontend.php new file mode 100644 index 00000000..76a0b984 --- /dev/null +++ b/packages/inertia-react/src/ReactInertiaFrontend.php @@ -0,0 +1,15 @@ +toBe('app/react-web/resources/js/app.jsx'); - expect($config['ssrEntry'])->toBe('app/react-web/resources/js/ssr.jsx'); - expect($config['ssrBundle'])->toBe('bootstrap/ssr/react/ssr.js'); +test('inertia-react config overlays the parent inertia config', function () { + $config = require dirname(__DIR__).'/config/inertia.php'; + + expect($config['assetEntry'])->toBe('app/react-web/resources/js/app.jsx'); + expect($config['ssr']['bundle'])->toBe('bootstrap/ssr/react/ssr.js'); + expect($config)->not->toHaveKey('ssrEntry'); +}); + +test('inertia-react binds the inertia frontend marker', function () { + $module = require dirname(__DIR__).'/module.php'; + + expect($module['bindings'])->toHaveKey(InertiaFrontendInterface::class) + ->and($module['bindings'][InertiaFrontendInterface::class])->toBe(ReactInertiaFrontend::class); +}); + +test('react inertia frontend identifies itself', function () { + expect((new ReactInertiaFrontend())->name())->toBe('react'); }); -test('inertia-react is a config-only marko module', function () { +test('inertia-react is a marko module', function () { $composer = json_decode( file_get_contents(dirname(__DIR__).'/composer.json'), true, flags: JSON_THROW_ON_ERROR, ); - expect(file_exists(dirname(__DIR__).'/module.php'))->toBeFalse() - ->and($composer['extra']['marko']['module'])->toBeTrue(); + expect(file_exists(dirname(__DIR__).'/module.php'))->toBeTrue() + ->and($composer['extra']['marko']['module'])->toBeTrue() + ->and($composer['autoload']['psr-4'])->toHaveKey('Marko\\Inertia\\React\\'); }); From 80bfe99417db87dfeb4869a9100bf789b6011c2e Mon Sep 17 00:00:00 2001 From: Mark Shust Date: Fri, 1 May 2026 20:43:39 -0400 Subject: [PATCH 5/5] refactor: align inertia-react with sibling conventions and trim pseudo-config - Nest test namespace as Marko\Inertia\React\Tests\ to match every other Marko driver sibling (Marko\Cache\File\Tests\, Marko\Database\PgSql\Tests\) - Drop ssr.bundle config slot from companion and parent (no PHP consumer; Marko's SSR client only reads inertia.ssr.enabled and inertia.ssr.url) - Link the Inertia.js docs reference in the npm install note - Document the inertia.assetEntry overlay slot in the parent inertia docs Refs #17. Co-Authored-By: Paulo Carvalho Co-Authored-By: Claude Opus 4.7 (1M context) --- composer.json | 2 +- docs/src/content/docs/packages/inertia-react.md | 6 +----- docs/src/content/docs/packages/inertia.md | 10 +++++++++- packages/inertia-react/composer.json | 2 +- packages/inertia-react/config/inertia.php | 3 --- packages/inertia-react/tests/InertiaReactTest.php | 1 - packages/inertia/config/inertia.php | 1 - packages/inertia/tests/InertiaTest.php | 1 - packages/inertia/tests/ModuleTest.php | 3 +-- 9 files changed, 13 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index d10c1eb2..0216e968 100644 --- a/composer.json +++ b/composer.json @@ -452,7 +452,7 @@ "Marko\\Hashing\\Tests\\": "packages/hashing/tests/", "Marko\\Health\\Tests\\": "packages/health/tests/", "Marko\\Inertia\\Tests\\": "packages/inertia/tests/", - "Marko\\InertiaReact\\Tests\\": "packages/inertia-react/tests/", + "Marko\\Inertia\\React\\Tests\\": "packages/inertia-react/tests/", "Marko\\Http\\Tests\\": "packages/http/tests/", "Marko\\Http\\Guzzle\\Tests\\": "packages/http-guzzle/tests/", "Marko\\Layout\\Tests\\": "packages/layout/tests/", diff --git a/docs/src/content/docs/packages/inertia-react.md b/docs/src/content/docs/packages/inertia-react.md index 46c57840..a793b568 100644 --- a/docs/src/content/docs/packages/inertia-react.md +++ b/docs/src/content/docs/packages/inertia-react.md @@ -17,7 +17,7 @@ Install the matching frontend dependencies in your app: npm install @inertiajs/react react react-dom @vitejs/plugin-react vite ``` -Refer to the Inertia.js docs for currently supported versions of each frontend adapter. +Refer to the [Inertia.js docs](https://inertiajs.com/) for currently supported versions of each frontend adapter. ## Configuration @@ -26,16 +26,12 @@ This package contributes defaults to the parent `config/inertia.php` namespace: ```php title="packages/inertia-react/config/inertia.php" return [ 'assetEntry' => env('INERTIA_REACT_CLIENT_ENTRY', 'app/react-web/resources/js/app.jsx'), - 'ssr' => [ - 'bundle' => env('INERTIA_REACT_SSR_BUNDLE', 'bootstrap/ssr/react/ssr.js'), - ], ]; ``` | Key | Purpose | | --- | --- | | `assetEntry` | Vite entry used by browser-rendered Inertia responses. | -| `ssr.bundle` | Relative path to the built SSR bundle loaded by your SSR runner. | ## Usage diff --git a/docs/src/content/docs/packages/inertia.md b/docs/src/content/docs/packages/inertia.md index 097e9a25..f28cff54 100644 --- a/docs/src/content/docs/packages/inertia.md +++ b/docs/src/content/docs/packages/inertia.md @@ -20,6 +20,7 @@ Configure via `config/inertia.php`: ```php title="config/inertia.php" return [ 'version' => null, + 'assetEntry' => null, 'ssr' => [ 'enabled' => env('INERTIA_SSR_ENABLED', false), 'url' => env('INERTIA_SSR_URL', 'http://localhost:13714'), @@ -30,6 +31,7 @@ return [ | Key | Purpose | | --- | --- | | `version` | Asset version included in every Inertia page object. Set to `null` to disable version mismatch handling. | +| `assetEntry` | Default Vite entry used by `render()` when no `$assetEntry` argument is passed. Frontend companion packages (`marko/inertia-react`, `marko/inertia-vue`, `marko/inertia-svelte`) overlay this slot via `config/inertia.php` so installing one swaps the entry without code changes. | | `ssr.enabled` | When true, the initial browser response attempts to render through the configured Inertia SSR server. | | `ssr.url` | URL used by the SSR client when SSR is enabled. | @@ -77,7 +79,13 @@ For a normal browser visit, `render()` returns the initial HTML shell with the p ### Asset Entries -By default, the HTML shell uses the configured `vite.entry`. Pass an asset entry to target a frontend-specific bundle: +The Vite entry resolves in this order: + +1. The `$assetEntry` argument passed to `render()` (highest priority). +2. The `inertia.assetEntry` config slot, typically populated by a frontend companion package (`marko/inertia-react`, `marko/inertia-vue`, `marko/inertia-svelte`). +3. The `vite.entry` fallback from `marko/vite`. + +Pass an asset entry per call to override the configured default: ```php return $this->inertia->render( diff --git a/packages/inertia-react/composer.json b/packages/inertia-react/composer.json index 0a098395..ccff5633 100644 --- a/packages/inertia-react/composer.json +++ b/packages/inertia-react/composer.json @@ -17,7 +17,7 @@ }, "autoload-dev": { "psr-4": { - "Marko\\InertiaReact\\Tests\\": "tests/" + "Marko\\Inertia\\React\\Tests\\": "tests/" } }, "extra": { diff --git a/packages/inertia-react/config/inertia.php b/packages/inertia-react/config/inertia.php index 225509b5..022c6047 100644 --- a/packages/inertia-react/config/inertia.php +++ b/packages/inertia-react/config/inertia.php @@ -4,7 +4,4 @@ return [ 'assetEntry' => env('INERTIA_REACT_CLIENT_ENTRY', 'app/react-web/resources/js/app.jsx'), - 'ssr' => [ - 'bundle' => env('INERTIA_REACT_SSR_BUNDLE', 'bootstrap/ssr/react/ssr.js'), - ], ]; diff --git a/packages/inertia-react/tests/InertiaReactTest.php b/packages/inertia-react/tests/InertiaReactTest.php index fc0e0436..22fc5af9 100644 --- a/packages/inertia-react/tests/InertiaReactTest.php +++ b/packages/inertia-react/tests/InertiaReactTest.php @@ -9,7 +9,6 @@ $config = require dirname(__DIR__).'/config/inertia.php'; expect($config['assetEntry'])->toBe('app/react-web/resources/js/app.jsx'); - expect($config['ssr']['bundle'])->toBe('bootstrap/ssr/react/ssr.js'); expect($config)->not->toHaveKey('ssrEntry'); }); diff --git a/packages/inertia/config/inertia.php b/packages/inertia/config/inertia.php index 7f35fb60..11e1145d 100644 --- a/packages/inertia/config/inertia.php +++ b/packages/inertia/config/inertia.php @@ -8,6 +8,5 @@ 'ssr' => [ 'enabled' => env('INERTIA_SSR_ENABLED', false), 'url' => env('INERTIA_SSR_URL', 'http://localhost:13714'), - 'bundle' => null, ], ]; diff --git a/packages/inertia/tests/InertiaTest.php b/packages/inertia/tests/InertiaTest.php index 66984583..9eece8ed 100644 --- a/packages/inertia/tests/InertiaTest.php +++ b/packages/inertia/tests/InertiaTest.php @@ -24,7 +24,6 @@ function createInertia(array $config = [], array $viteConfig = []): Inertia 'inertia.assetEntry' => null, 'inertia.ssr.enabled' => false, 'inertia.ssr.url' => 'http://localhost:13714', - 'inertia.ssr.bundle' => null, 'vite.entry' => 'app/web/resources/js/app.js', 'vite.buildDirectory' => 'build', 'vite.manifestFilename' => '.vite/manifest.json', diff --git a/packages/inertia/tests/ModuleTest.php b/packages/inertia/tests/ModuleTest.php index c6490e48..d202d40f 100644 --- a/packages/inertia/tests/ModuleTest.php +++ b/packages/inertia/tests/ModuleTest.php @@ -31,6 +31,5 @@ expect($config['version'])->toBeNull() ->and($config['assetEntry'])->toBeNull() ->and($config['ssr']['enabled'])->toBeFalse() - ->and($config['ssr']['url'])->toBe('http://localhost:13714') - ->and($config['ssr']['bundle'])->toBeNull(); + ->and($config['ssr']['url'])->toBe('http://localhost:13714'); });