Skip to content

Commit 9848b55

Browse files
#559044: fixed rendering dynamic placeholder
1 parent 8b8d227 commit 9848b55

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

packages/sitecore-jss-react/src/components/PlaceholderCommon.tsx

+11-7
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ import {
1212
import { convertAttributesToReactProps } from '../utils';
1313
import { HiddenRendering, HIDDEN_RENDERING_NAME } from './HiddenRendering';
1414

15-
/** [SXA] common marker by which we find container fo replacing **/
16-
const PREFIX_PLACEHOLDER = 'container-{*}';
17-
1815
type ErrorComponentProps = {
1916
[prop: string]: unknown;
2017
};
@@ -121,10 +118,17 @@ export class PlaceholderCommon<T extends PlaceholderProps> extends React.Compone
121118
) {
122119
let result;
123120
/** [SXA] it needs for deleting dynamics placeholder when we set him number(props.name) of container.
124-
from backend side we get common name of placeholder is called 'container-{*}' where '{*}' marker for replacing **/
125-
if (rendering && rendering.placeholders && rendering.placeholders[PREFIX_PLACEHOLDER]) {
126-
rendering.placeholders[name] = rendering.placeholders[PREFIX_PLACEHOLDER];
127-
delete rendering.placeholders[PREFIX_PLACEHOLDER];
121+
from backend side we get common name of placeholder is called 'nameOfContainer-{*}' where '{*}' marker for replacing **/
122+
const isExistsDynamicPlaceholders =
123+
rendering?.placeholders &&
124+
Object.keys(rendering.placeholders).find((placeholder) => placeholder.indexOf('{*}') !== -1);
125+
if (isExistsDynamicPlaceholders) {
126+
Object.keys(rendering.placeholders).forEach((placeholder) => {
127+
if (placeholder.indexOf('{*}') !== -1) {
128+
rendering.placeholders[name] = rendering.placeholders[placeholder];
129+
delete rendering.placeholders[placeholder];
130+
}
131+
});
128132
}
129133

130134
if (rendering && rendering.placeholders && Object.keys(rendering.placeholders).length > 0) {

packages/sitecore-jss-react/src/test-data/non-ee-data.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export const sxaRenderingVariantDataWithoutCommonContainerName = {
245245
},
246246
},
247247
placeholders: {
248-
'no-container-{*}': [
248+
'no-container': [
249249
{
250250
uid: 'c4d5d43b-5aa8-4e03-8f16-9428f3e02d5c',
251251
componentName: 'RichText',

0 commit comments

Comments
 (0)