beromir / neos-inertia
Inertia.js adapter for Neos 9: Svelte (or any Inertia client) renders the pages, Neos Studio edits them
Requires
- php: ^8.4
- neos/neos: ^9.2
Requires (Dev)
None
Suggests
- medienreaktor/neos-studio: In-page editing of the rendered pages
Provides
None
Conflicts
None
Replaces
None
README
An Inertia.js adapter for Neos 9. Svelte (or any Inertia client) renders the pages, on the server and in the browser, and Neos Studio edits them in place.
- Live site: server-rendered HTML that hydrates, then Inertia visits (JSON) between pages, with persistent layouts.
- Neos Studio: the same server-rendered markup with Neos' editing attributes, not hydrated. Inline editing, the inspector, adding, moving, hiding and publishing work, and an edited element is re-rendered and swapped in place.
- Caching: each page is one entry in Neos' content cache, kept apart for HTML, JSON and outdated asset versions, and flushed by any change below the document, to any document (menus) or to the site node.
Status: first working version. Tested with Neos 9.2, Neos Studio 2.6, Inertia 3.7 and Svelte 5.
How it works
flowchart LR
req[Request] --> fusion["Document prototype<br/>Beromir.Inertia:Page"]
fusion --> mapper["NodeMapper (PHP)<br/>nodes to props"]
mapper --> kind{Inertia visit?}
kind -- yes --> json[Page object as JSON]
kind -- no --> ssr["Renderer (Node)<br/>/render"] --> shell[HTML shell]
studio[Studio after an edit] --> api["Neos.Api fusionPathHtml"] --> frag["Beromir.Inertia:Fragment"] --> ssrf["Renderer<br/>/render-fragment"]
Loading
Fusion is only the entry point: Neos and Studio render documents and single elements through Fusion paths. Sites write no Fusion beyond choosing a page component.
Beromir.Inertia:Pageis the base prototype for document node types. It maps the document to props in PHP and answers an Inertia visit with the page object as JSON, a visit with an outdated asset version with 409, and every other request with the HTML shell around the server-rendered app.Beromir.Inertia:Fragmentrenders one content element for Studio's in-place updates. Every element'sdata-__neos-fusion-pathpoints there. A content collection is rendered through the element it belongs to, because its markup is that component's.- The renderer is a small Node server from
@beromir/neos-inertia-svelte, with Inertia's page rendering at/renderand single components at/render-fragment. That package also has the Svelte components that put the props on the page.
Props
Every page gets:
| Prop | What |
|---|---|
document |
The document node, with uri |
site |
{id, title, uri} |
menu |
{home, items}: the site's documents two levels deep, each with a state (current, active, normal); documents with hiddenInMenu are left out |
neos |
{backend, editMode, renderingMode} |
Add more in Fusion with props.<name>. Nodes, images, assets and dates in them are mapped like node properties.
A node becomes {id, nodeType, component, properties, collections}, a content collection {id, nodeType, component, nodes}:
componentis the node type'soptions.beromirInertia.component, else its name after the package key with dots as slashes (Vendor.Site:Content.TextbecomesContent/Text).properties: inline-editable properties as their HTML (links resolved on the live site); images as{src, srcset, width, height, alt}(widths fromBeromir.Inertia.imageWidths); assets as{uri, title, filename, mediaType};node://andasset://links as URLs. Properties starting with_are left out. References are not mapped yet.collections: the node's tethered content collections by name.- In the backend,
$wrapholds the attributes of the element that stands for the node, and$editablethose of each inline-editable property's element. They come fromNeos.Neos:ContentElementWrappingandNeos.Neos:Editable, so whatever Studio (or another package) adds to those prototypes is included.
A property is edited as a single line (no paragraphs) when its ui.inline.editorOptions.autoparagraph is false.
Setup
# Configuration/Settings.yaml of the site package Beromir: Inertia: assets: entry: 'DistributionPackages/Vendor.Site/Resources/Private/Frontend/app.ts' # the key in Vite's manifest manifest: 'resource://Vendor.Site/Public/Build/.vite/manifest.json' publicPath: 'resource://Vendor.Site/Public/Build' ssr: url: 'http://127.0.0.1:13714' timeout: 2
# Resources/Private/Fusion/Root.fusion of the site package
prototype(Vendor.Site:Document.Page) < prototype(Beromir.Inertia:Page) {
component = 'Page'
props.footer = ${q(site).children('footer').get(0)}
# shared content outside the document needs a tag of its own
@cache.entryTags.footer = ${Neos.Caching.descendantOfTag(q(site).children('footer').get(0))}
}
Install the client side with npm install @beromir/neos-inertia-svelte. The development distribution (neos-inertia) has a complete demo site: node types, the Vite config, the browser and server entries and the components.
Caching
The page is cached as one entry, tagged with the document, everything below it, every document (for the menu) and the site node. BeromirInertia.cacheIdentifier(request) is added to Neos.Fusion:GlobalCacheIdentifiers, so every cache entry is kept apart per kind of request (HTML, JSON, outdated version) and per asset version.
The renderer is required. When it can't be reached, the page fails with an error, which is not cached; cached pages are still served. The editor gets no browser rendering, so it can't fall back to one.
Limits of this version
- No partial reloads (
X-Inertia-Partial-Data): every visit gets all props. - References, forms, flash messages and validation errors are not mapped.
- Interactive components don't run in the editor, since the page is not hydrated there.
- One site per installation: the asset settings are global.
- Neos writes the dimension space point of a content repository without dimensions as
[]in node addresses, which Neos.Api rejects. The adapter rewrites it to{}in the editing attributes.