Skip to content

Commit

Permalink
TASK: Don’t render nodedata to content and just load on initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebobo committed Apr 24, 2024
1 parent 06d7cd1 commit 5242e1d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 47 deletions.
22 changes: 1 addition & 21 deletions Classes/Aspects/AugmentationAspect.php
Expand Up @@ -38,24 +38,12 @@ class AugmentationAspect
*/
protected $nodeAuthorizationService;

/**
* @Flow\Inject
* @var UserLocaleService
*/
protected $userLocaleService;

/**
* @Flow\Inject
* @var HtmlAugmenter
*/
protected $htmlAugmenter;

/**
* @Flow\Inject
* @var NodeInfoHelper
*/
protected $nodeInfoHelper;

/**
* @Flow\Inject
* @var SessionInterface
Expand Down Expand Up @@ -126,15 +114,7 @@ public function contentElementAugmentation(JoinPointInterface $joinPoint)
$attributes['data-__neos-node-contextpath'] = $node->getContextPath();
$attributes['data-__neos-fusion-path'] = $fusionPath;

$this->userLocaleService->switchToUILocale();

$serializedNode = json_encode($this->nodeInfoHelper->renderNodeWithMinimalPropertiesAndChildrenInformation($node, $this->controllerContext));
$attributes['data-__neos-nodedata'] = $serializedNode;

$this->userLocaleService->switchToUILocale(true);

$wrappedContent = $this->htmlAugmenter->addAttributes($content, $attributes, 'div');
return $wrappedContent;
return $this->htmlAugmenter->addAttributes($content, $attributes);
}

/**
Expand Down
35 changes: 9 additions & 26 deletions packages/neos-ui-guest-frame/src/initializeGuestFrame.js
Expand Up @@ -16,7 +16,7 @@ import {

import style from './style.module.css';
import {SelectionModeTypes} from '@neos-project/neos-ts-interfaces';
import backend from "@neos-project/neos-ui-backend-connector";
import backend from '@neos-project/neos-ui-backend-connector';

//
// Get all parent elements of the event target.
Expand Down Expand Up @@ -64,25 +64,18 @@ export default ({globalRegistry, store}) => function * initializeGuestFrame() {
// Load legacy node data scripts from guest frame - remove with Neos 9.0
const legacyNodeData = guestFrameWindow['@Neos.Neos.Ui:NodeData'] || {};

// Load nodedata from augmented nodes in guest frame
const embeddedNodeData = {};
Array.prototype.forEach.call(
guestFrameWindow.document.querySelectorAll('[data-__neos-nodedata]'),
(element) => {
const contextPath = element.dataset.__neosNodeContextpath;
try {
embeddedNodeData[contextPath] = JSON.parse(element.dataset.__neosNodedata);
element.removeAttribute('data-__neos-nodedata');
} catch (e) {
console.error('Could not parse node data for context path', contextPath, e);
}
}
);
// Load all nodedata from content at the end of the initialisation to avoid blocking the UI
const {q} = yield backend.get();
const nodeContextPathsInGuestFrame = findAllNodesInGuestFrame().map(node => node.getAttribute('data-__neos-node-contextpath'));
const fullyLoadedNodesFromContent = (yield q(nodeContextPathsInGuestFrame).get()).reduce((nodes, node) => {
nodes[node.contextPath] = node;
return nodes;
}, {});

const nodes = Object.assign(
{},
legacyNodeData, // Merge legacy node data from the guest frame - remove with Neos 9.0
embeddedNodeData,
fullyLoadedNodesFromContent,
{
[documentInformation.metaData.documentNode]: documentInformation.metaData.documentNodeSerialization
}
Expand Down Expand Up @@ -234,14 +227,4 @@ export default ({globalRegistry, store}) => function * initializeGuestFrame() {
node.classList.remove(style['markActiveNodeAsFocused--focusedNode']);
}
});

// Load all nodedata from content at the end of the initialisation to avoid blocking the UI
const {q} = backend.get();
const fullyLoadedNodesInContent = yield q(Object.keys(embeddedNodeData)).get();
if (fullyLoadedNodesInContent) {
yield put(actions.CR.Nodes.merge(fullyLoadedNodesInContent.reduce((nodes, node) => {
nodes[node.contextPath] = node;
return nodes;
}, {})));
}
};

0 comments on commit 5242e1d

Please sign in to comment.