neos / neos-ui

Neos CMS UI written in ReactJS with Immutable data structures.
GNU General Public License v3.0
264 stars 136 forks source link

`globalRegistry.get('frontendConfiguration')` doesnt work in plugin/manifest bootstrap #3098

Open mhsdesign opened 2 years ago

mhsdesign commented 2 years ago

Description

when one registers a new plugin in the manifest and tries to call globalRegistry.get('frontendConfiguration') null is returned.

Steps to Reproduce

  1. Write a manifest like:
    import manifest from '@neos-project/neos-ui-extensibility';
    manifest('Fooo', {}, (globalRegistry) => {
    console.log(globalRegistry.get('frontendConfiguration'))
    }

    Expected behavior

to get the actual FrontendConfigurationSynchronousRegistry

Actual behavior

we log null

What actually happened

the FrontendConfigurationSynchronousRegistry is not initialized, when the bootstraps are called.

the manifests are booted here in line 76 https://github.com/neos/neos-ui/blob/6ce277470258599c1d29f9ec2f5983e7e44d4338/packages/neos-ui/src/index.js#L76

but only in line 121 https://github.com/neos/neos-ui/blob/6ce277470258599c1d29f9ec2f5983e7e44d4338/packages/neos-ui/src/index.js#L121-L127 the raw yaml / php-array frontendConfiguration array is transferred to a SynchronousRegistry

... Sure we can get hold of the frontendConfiguration in another way:

  1. Write a manifest like:
    manifest('Fooo', {}, (globalRegistry, { frontendConfiguration }) => {
    console.log(frontendConfiguration)
    }

    now it works, but note that this is the raw yaml / php-array and not a SynchronousRegistry so frontendConfiguration.get('My.Package') doesnt work (one needs to use normal array access like frontendConfiguration['My.Package']) - but it does other places (when you actually have the FrontendConfigurationSynchronousRegistry)

Outcome

is there a reason, why the FrontendConfigurationSynchronousRegistry is not initialized before boot and passed? im now used to this but i find this behavior odd - and would like to have at all places a FrontendConfigurationSynchronousRegistry available.

Affected Versions

UI: Since ever

mhsdesign commented 1 year ago

Same applies for i18n - the translations are not available at first. setTranslations will only be called, after the manifests are bootet.

A workaround is to register a saga which waits until the system initializes (when the frontent config and translations are loaded.)

import manifest from "@neos-project/neos-ui-extensibility";
import { take } from 'redux-saga/effects';
import { actionTypes } from '@neos-project/neos-ui-redux-store';

manifest("Mhs.Bar", {}, (globalRegistry) => {
    const i18n = globalRegistry.get("i18n")

    function* onSystemInit() {
        yield take(actionTypes.System.INIT)
        console.log(i18n.translate('Mhs.Bar:Main:nix'));
    }

    const sagasRegistry = globalRegistry.get('sagas');
    sagasRegistry.set('CodeQ.NeosUiTranslateRteStyleSelect/init', { saga: onSystemInit });
});
mhsdesign commented 1 year ago

im wondering if the above described behavior for the config is intentional, as one could technically even mutate the second param of the bootstrap callback { frontendConfiguration } before its added to the global registry ...