Download the PHP package leon-wbr/inertia-typo3 without Composer
On this page you can find all versions of the php package leon-wbr/inertia-typo3. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download leon-wbr/inertia-typo3
More information about leon-wbr/inertia-typo3
Files in leon-wbr/inertia-typo3
Package inertia-typo3
Short Description A TYPO3 adapter for Inertia.js.
License GPL-3.0-or-later
Homepage https://github.com/leon-wbr/inertia-typo3
Informations about the package inertia-typo3
Status: before 1.0. v0.1.0 is on Packagist. The adapter implements the Inertia 3 protocol and is tested against the official React, Vue and Svelte clients, but its PHP API can still change between minor releases until 1.0. Compared with inertia-laravel lists what is missing. Feedback and issues are welcome.
TYPO3 Inertia Adapter
A TYPO3 extension providing the server side of Inertia.js 3: TYPO3 keeps routing, languages, access, redirects and the page cache, and answers with Inertia page objects that a React, Vue or Svelte frontend renders.
It follows the official inertia-laravel 3.x adapter where TYPO3 allows.
Contents:
- requirements
- verification
- Installation in your own project
- Usage: shared props, page components, forms, flash data, once props, infinite scroll, testing and settings
- Compared with inertia-laravel
- license
Features
- The Inertia 3 protocol: the
<script type="application/json">page element, JSON responses for Inertia visits, asset versioning (409 withX-Inertia-Location), 303 redirects afterPUT,PATCHandDELETE, and redirects with fragments (X-Inertia-Redirect). - Partial reloads (
only,except, nested paths), with deferred, optional, always and merge props, including deep merge, prepend andmatchOn. - Validation errors and error bags: flashed across the redirect in the TYPO3 frontend session (anonymous visitors included), always shared as the
errorsprop, scoped byX-Inertia-Error-Bag, and cleared once read. - Flash data, sent once as the page object's
flash. - Once props (
onceProps,X-Inertia-Except-Once-Props), with custom keys, expiry and refresh. - Scroll props for
<InfiniteScroll>(scrollProps, the merge intent header), from TYPO3's core paginators or plain arrays. - Shared props, resolved lazily when a page is rendered, and shared once props.
- History encryption and clearing flags.
- Testing helpers for TYPO3 functional tests, like inertia-laravel's
assertInertia(). - JSON request bodies parsed for Inertia forms.
- A page plugin that renders TYPO3 pages with their content elements, through the core Record API, with TypoScript-rendered HTML as fallback.
- A navigation builder that respects translations, hidden pages, start and end times, access groups and workspaces.
Requirements
| Version | |
|---|---|
| TYPO3 | 14.3 |
| PHP | 8.2 to 8.5 |
| Inertia.js client | 3.x |
TYPO3 13.4 is no longer supported; the earlier 13.4 proof of concept stays in the git history.
Quickstart with DDEV
The repository contains a runnable example project in example/packages/sitepackage with a React 19 frontend, an English and a German page tree, and the verification suite.
The backend is at /typo3 (user admin, password Password1!).
For frontend work, run the Vite dev server instead of the build. Start it from example/, because ddev vite runs in the matching directory inside the container:
While it runs, it writes example/var/vite-dev-server, and TYPO3 loads assets from the dev server with hot module replacement; flush the TYPO3 caches (ddev exec -d /var/www/html/example vendor/bin/typo3 cache:flush) for already cached pages. Stop it (Ctrl+C) and TYPO3 serves the production build again. If the dev server crashed instead, delete example/var/vite-dev-server yourself.
The DDEV project runs PHP 8.5, MariaDB 10.11 and Node.js 26 (LTS) with pnpm 12, and needs DDEV 1.25 or later.
Verification
runs everything from scratch and exits non-zero on the first failure:
composer install,pnpm install, a fresh database,typo3 setupand the example content;composer validate, PHP CS Fixer and PHPStan (level 9, with a baseline of the errors that existed when the level was raised);- PHPUnit unit and functional tests (TYPO3 testing framework, SQLite), and the unit tests again with pcov, failing below the minimum line coverage set in
example/composer.json, then mutation testing of the middleware, props and services with Infection (composer test:mutationinexample/), failing below the minimum MSI inBuild/phpunit/infection.json5; - the Inertia parity check: the protocol surface in
Build/Parity/parity.jsonagainst the installed@inertiajs/core(see TODO.md); - ESLint, Prettier and the TypeScript 7 typecheck;
- a Vite production build;
- Playwright end-to-end tests against the site serving that build: first load, Inertia navigation, asset version mismatch, form redirects with validation errors and flash data, query strings, partial reloads, deferred, optional, merge and once props, infinite scroll, and the second language.
GitHub Actions runs the same command on pushes to main and on pull requests. ddev outdated lists outdated Composer and pnpm dependencies of the example.
For the PHP part alone, run composer check in example/ (code style, PHPStan and both test suites, without DDEV once composer install has run there), or one of composer cs, cs:fix, stan, test:unit, test:functional and test:coverage (needs pcov or Xdebug).
Conformance with the official clients
runs the official Inertia clients, @inertiajs/react, @inertiajs/vue3 and @inertiajs/svelte, against a TYPO3 project of their own with this adapter. Every case of the protocol conformance list is a test, and known gaps are expected failures. After a run, the case × client matrix is in conformance/matrix.md. GitHub Actions runs it on every branch push and shows the matrix in the job summary. See conformance/README.md.
Installation in your own project
The root view below loads the frontend with praetorius/vite-asset-collector, as the example does. The adapter doesn't require it, so install it too if you want the same setup:
Any other way of adding your script and style tags works as well. Then point the extension setting manifestPath at your build's manifest (see Settings), because its hash is the asset version.
Then:
- Add the site set
leon-wbr/inertiato your site (or a sitepackage set that depends on it). It renders every page through the page plugin. -
Provide a root view: a Fluid template
App.htmlin a path you add toplugin.tx_inertia.view.templateRootPaths. It renders the page element and your entry point: -
Set up the client. For React:
TYPO3 pages render the component
Default(seemain.tsxis a complete entry point.
Starting from the example sitepackage
example/packages/sitepackage is the example's sitepackage and a complete starter: the root view, shared props (site, languages, navigation), page components chosen by frontend layout, content elements rendered by React or from TYPO3's HTML, and a contact form. To start your own project from it:
- Copy
example/packages/sitepackageinto your project'spackages/directory, and rename the Composer package, the extension key and the PHP namespace if you like. -
Add a path repository for it and require it:
- Add its site set
leon-wbr/inertia-sitepackageto your site. It pulls in the adapter's set and fluid_styled_content. - Build the frontend in your project root, as the example does: copy
example/package.json,example/vite.config.ts,example/tsconfig.jsonandexample/eslint.config.js(drop the Playwright parts you don't need), thenpnpm installandpnpm build.
See the sitepackage README for what it contains.
Usage
Shared props
Replace the adapter's middleware with your own subclass, registered under the same identifier in your extension's Configuration/RequestMiddlewares.php:
Page component and props
Pages render the component from the site setting inertia.component (default Default) with the props title and contentElements. Listen to BeforeInertiaPageRenderedEvent to pick another component or add props:
In your own Extbase controllers or middlewares, use InertiaService directly: render(), location(), redirect(), share(), shareOnce(), always(), optional(), defer(), merge(), deepMerge(), once(), scroll(), withErrors(), flash(), encryptHistory() and clearHistory().
Forms and validation errors
Handle the submission, flash the errors and redirect back. The errors are stored in the TYPO3 frontend user session, which works for anonymous visitors too (TYPO3 sets its session cookie once something is stored), and arrive on the next page as the errors prop:
errorsis shared with every page as an always prop (included in partial reloads), and is{}without errors. Errors are cleared once a page has been rendered with them.- A field can have a list of messages; the first one is sent. Set
protected bool $withAllErrors = true;in your middleware subclass to send them all. - Error bags:
withErrors($errors, 'login')stores them in a named bag. A request withX-Inertia-Error-Bag: contact(<Form errorBag="contact">orrouter.post(url, data, { errorBag: 'contact' })) gets the default bag aserrors.contact, and the client scopes the form's errors to it.
The example's contact form works this way.
Flash data
$this->inertia->flash('success', 'Saved') (or an array) stores data for the next page the client renders. As in inertia-laravel 3.x, it is sent as the page object's flash key, not as a prop: read it with usePage().flash, or router.on('flash', …) for toasts. It is sent once and then cleared. Type it with flashDataType in InertiaConfig.
Once props
A once prop is resolved once and then kept by the client: on later visits the client lists the once props it has in X-Inertia-Except-Once-Props, and the server skips them.
as()sets the key the client remembers it by (default: the prop path),until()sets an expiry (seconds, aDateIntervalor aDateTimeInterface),fresh()sends it anyway.- Deferred, optional and merge props can be once props too (
->once()). - Share once props with every page from your middleware's
shareOnce()(orInertiaService::shareOnce()):
Infinite scroll
scroll() makes a prop for <InfiniteScroll>. The page announces it in scrollProps (page name, previous, next and current page), and each page the client loads is appended to the items, or prepended when it scrolls up (X-Inertia-Infinite-Scroll-Merge-Intent).
- The client sends the page in the
pagequery parameter. TYPO3 paginators don't know that name: passpageName:if you use another one. Add the parameter to$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParameters'], as the example sitepackage does, so TYPO3 doesn't ask for a cHash. - The items are under
data; pass another wrapper key as the second argument. A metadata callback (fn($value) => new ScrollMetadata(...)) or anyProvidesScrollMetadataworks too. ->defer()loads the first page right after the page instead of with it.
Testing
LeonWbr\Inertia\Testing\InteractsWithInertia is a trait for functional tests with typo3/testing-framework, like inertia-laravel's assertInertia():
inertiaRequest($uri)builds an Inertia visit,inertiaReloadRequest($uri, $component, only: [...], except: [...])a partial reload.assertInertia()reads JSON responses and the page script of a first visit (plainInternalRequest).- Props are addressed by dot paths. Also:
hasAll(),prop(),hasError(),hasPrependProps(),hasDeepMergeProps(),hasFlash(),missingFlash(),url()andtoArray(). - For a session (errors and flash across a redirect), send the
fe_typo_usercookie of the POST response with the next request (withCookieParams()); see the adapter's own functional tests.
Settings
| Site setting | Default | |
|---|---|---|
inertia.component |
Default |
Page component for TYPO3 pages |
inertia.contentElements.typedTypes |
none | CTypes your frontend renders itself; their HTML fallback is skipped |
inertia.contentElements.properties |
common tt_content fields |
Fields sent as data; empty sends all |
The extension setting manifestPath (default _assets/vite/.vite/manifest.json) is the file whose hash is the asset version.
Compared with inertia-laravel
The adapter follows inertia-laravel 3.x, the reference server adapter. TODO.md has the full audit against the latest Inertia releases: every feature with its source, status, tests and priority, the next steps, and how the list is kept in sync.
| Feature | inertia-laravel 3.x | This adapter |
|---|---|---|
Page object, JSON responses, <script> page element |
✓ | ✓ |
Asset versioning (409 + X-Inertia-Location) |
✓ | ✓ (hash of the Vite manifest) |
303 after PUT, PATCH, DELETE; fragment redirects |
✓ | ✓ |
External redirects (Inertia::location()) |
✓ | ✓ location() |
| Shared props, lazy closures, dot keys | ✓ | ✓ |
Partial reloads (only, except, nested paths) |
✓ | ✓ |
| Always, optional, deferred props (groups) | ✓ | ✓ |
Merge, prepend, deep merge, matchOn |
✓ | ✓ |
Once props (once(), as(), until(), fresh(), shareOnce()) |
✓ | ✓ |
Scroll props for <InfiniteScroll> |
✓ (Laravel paginators) | ✓ (TYPO3 paginators, arrays) |
Validation errors, error bags, withAllErrors |
✓ (Laravel session) | ✓ (TYPO3 frontend session) |
Flash data (page flash) |
✓ | ✓ |
| History encryption and clearing | ✓ (also as middleware) | ✓ (flags on InertiaService) |
| Testing assertions | ✓ assertInertia() |
✓ InteractsWithInertia, AssertableInertia |
Reloads and deferred props in testing assertions (reloadOnly(), loadDeferredProps()) |
✓ | – build them with inertiaReloadRequest() |
| Server-side rendering | ✓ | – planned |
| Live props (broadcasting) | ✓ | – |
Rescued deferred props (rescue) |
✓ | – |
ProvidesInertiaProperties, Arrayable and Responsable props |
✓ | – (JsonSerializable works) |
BigInt preservation, preserveFragment across redirects |
✓ | – |
| Precognition | ✓ | – |
| Dev tools | ✓ | – |
| Component existence check in tests | ✓ | – |
Roadmap
- Server-side rendering, in its own pull request.
- Rescued deferred props and BigInt preservation, if there is demand.
- Publishing to the TYPO3 Extension Repository.
Support
Questions and ideas go to GitHub Discussions, bugs to GitHub Issues.
Contributing
See the Contributing Guidelines. Run ddev verify before opening a pull request.
License
This project is licensed under the GNU General Public License v3.0 or later (GPL-3.0-or-later). See the LICENSE file for details.
All versions of inertia-typo3 with dependencies
typo3/cms-core Version ^14.3.10
typo3/cms-extbase Version ^14.3.10
typo3/cms-fluid Version ^14.3.10
typo3/cms-frontend Version ^14.3.10