Skip to content

Conversation

@mhsdesign
Copy link
Member

@mhsdesign mhsdesign commented Oct 13, 2025

TASK: Introduce api to use global state for configuration and global registry

Originally the Neos Ui was build seemingly without real global state. There is a high order component function - invoked via a decorator @neos() which allowed to inject the registry which was distributed via react context.

For functional components currently one would need to use the same high-order-pattern which is a little quirky with functions compared to say the new concept of hooks.

The use of hooks as approach was shown in @sitegeist-archeaopteryx/neos-bridge we would continue to use the NeosContext and fetch the global registry or configuration from there via hooks like

  • useNeos()
  • useGlobalRegistry()
  • useI18n()
  • useConfiguration()

but as this information is truly global and never leads to a re-rendering e.g. is static. We dont have to make that look like a hook but just use javascript state instead. (Like we do for the new translate() function)

This change introduces a new package "@neos-project/neos-ui-registry" to host the global registry as singleton

import {getGlobalRegistry, getRegistryById} from '@neos-project/neos-ui-registry';

const globalRegistry = getGlobalRegistry();
globalRegistry.get('...');
globalRegistry.set('...', ...);

// alias as "get" is common enough
const validators = getRegistryById('validators');

Plugins

Further as part of this refactoring to move correlated code better together - the SynchronousRegistry and SynchronousMetaRegistry are moved to the new @neos-project/neos-ui-registry package.

This has an implication as those are exposed via extensibility api - plugins using import {SynchronousRegistry} from '@neos-project/neos-ui-extensibility' must update this to use import {SynchronousRegistry} from '@neos-project/neos-ui-registry'. This is a soft breaking change as we do not require anyone to update their @neos-project/neos-ui-extensibility package. Previously build plugins continue to work. BUT to also allow plugins build this new way a patch must be made to 9.0 which provides @neos-project/neos-ui-registry already for plugins.

-> or we decide to target 9.0 instead.

Typings 🥳

Also we now have improved typescript support for the globalRegistry - at least with a few registries:

image

What I did

How I did it

How to verify it

@mhsdesign
Copy link
Member Author

mhsdesign commented Oct 15, 2025

In some (minor) regards this change itself is not finished -> it definitely needs the followup #4012 but id prefer to merge these as separate parts

@mhsdesign mhsdesign force-pushed the task/use-functional-components-without-neos-decorator branch from 56c6639 to 25607d6 Compare October 15, 2025 18:32
Copy link
Member

@Sebobo Sebobo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but we have to be careful with any changes to the extensibility package

@mhsdesign
Copy link
Member Author

mhsdesign commented Oct 17, 2025

Regarding that we no longer expose SynchronousRegistry when doing import {SynchronousRegistry} from '@neos-project/neos-ui-extensibility' -> i know that this might cause adjustments in the plugins and i also wrote about that above under "Plugins".

At first i thought we could provide a b/c layer to still support that but that might be impossible due to the global state initialisation.

I think the important part is that few people used SynchronousRegistry and that already build plugins continue to work and that if people update their extensibility yarn package @neos-project/neos-ui-extensibility from 9.0.2 to this planned upcoming 9.0.3 that yes they have to rewrite the import to import {SynchronousRegistry} from '@neos-project/neos-ui-registry' -> but i believe this might be preferred over to targeting that change only to 9.1 which would mean that plugins build with `'@neos-project/neos-ui-registry'`` would not work on a Neos 9.0 host ... if we merge into 9.0.3 these plugins would at least work with Neos 9.0.3 and above.

If we consider this a bad deal still and want to preserve full yarn semver promise i will find a way to make import {SynchronousRegistry} from '@neos-project/neos-ui-extensibility' work -> even if we need to duplicate code.

EDIT @Sebobo found a way to support the "SynchronousRegistry" still 744659a

@Sebobo
Copy link
Member

Sebobo commented Oct 17, 2025

EDIT @Sebobo found a way to support the "SynchronousRegistry" still 744659a

Thx. Cool, less breaky, more happy and yes I agree, we should keep targeting 9.0 with this.

@mhsdesign mhsdesign requested a review from Sebobo October 17, 2025 12:20
@mhsdesign mhsdesign force-pushed the task/use-functional-components-without-neos-decorator branch from 25607d6 to 7782c18 Compare October 19, 2025 11:03
Copy link
Member Author

@mhsdesign mhsdesign left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I applied some git magic to backport some of the fixups from the other pr to here ;) Now this pr is independent ;)

And as you agree ill probably merge it soon before the sprint^^

@mhsdesign mhsdesign force-pushed the task/use-functional-components-without-neos-decorator branch from 7782c18 to 8958f0c Compare October 28, 2025 12:23
Originally the Neos Ui was build seemingly without real global state. There is a high order component function - invoked via a decorator @neos() which allowed to inject the registry.

For functional components currently one would need to use the same high-order-pattern which is a little quirky with functions compared to say the new concept of hooks.

The use of hooks as approach was shown in `@neos-project/neos-ui-link-editor-neos-bridge` we would continue to use the NeosContext and fetch the global registry or configuration from there via hooks like

- useNeos()
- useGlobalRegistry()
- ...useConfiguration()

but as this information is truly global and never leads to a re-rendering e.g. is static. We dont have to make that look like a hook but just use javascript state instead. (Like we do for the new translate() function)
… `@neos-project/neos-ui-registry` package

and alias and expose it via extensibility api - plugins using `import {SynchronousRegistry} from '@neos-project/neos-ui-extensibility'` must update this to use `import {SynchronousRegistry} from '@neos-project/neos-ui-registry'`
…ule overloading for extending it to know "i18n" etc
... and also instantiate validators registry here
…repository` package and register type in global registry
…w null

as called with

```
const referenceGrandParentNodeType = referenceParentNode ? referenceParentNode.nodeType : null;
```
Hi style ci do you see this:

"""""""""""""""""""""""""""""""""""""""""""""""""""""

hope youre "happy"
…pi for plugins but preserver compatibility with `SynchronousRegistry` legacy import
@mhsdesign mhsdesign force-pushed the task/use-functional-components-without-neos-decorator branch from 8958f0c to 11b4b49 Compare October 28, 2025 13:35
…rating types declaration

otherwise typescript attempts to parse the whole neos ui repo and that fails
…n "neos-ui-extensibility"

this is because the SynchronousRegistry is no longer shipped as plain code using the "positional-array-sorter" but exposed via the consumer api
@mhsdesign mhsdesign force-pushed the task/use-functional-components-without-neos-decorator branch from 11b4b49 to ab14d04 Compare October 28, 2025 21:08
@mhsdesign mhsdesign merged commit 1e44c7b into neos:9.0 Oct 28, 2025
6 of 7 checks passed
mhsdesign added a commit that referenced this pull request Oct 29, 2025
we need to use "noResolve" otherwise typescript runs into:

 Cannot find module './style.module.css' or its corresponding type declarations.

 Fixup for #4011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants