From 4ea36e8b54d4e0be5716be156ca96ab9cbeb5770 Mon Sep 17 00:00:00 2001 From: Ruslan Matkovskyi Date: Wed, 4 Jan 2023 18:05:31 +0100 Subject: [PATCH] #559044: fixed rendering dynamic placeholder --- .../src/components/PlaceholderCommon.tsx | 15 ++++++++------- .../src/test-data/non-ee-data.ts | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/sitecore-jss-react/src/components/PlaceholderCommon.tsx b/packages/sitecore-jss-react/src/components/PlaceholderCommon.tsx index ff28cb83f8..f424b55148 100644 --- a/packages/sitecore-jss-react/src/components/PlaceholderCommon.tsx +++ b/packages/sitecore-jss-react/src/components/PlaceholderCommon.tsx @@ -12,9 +12,6 @@ import { import { convertAttributesToReactProps } from '../utils'; import { HiddenRendering, HIDDEN_RENDERING_NAME } from './HiddenRendering'; -/** [SXA] common marker by which we find container fo replacing **/ -const PREFIX_PLACEHOLDER = 'container-{*}'; - type ErrorComponentProps = { [prop: string]: unknown; }; @@ -121,10 +118,14 @@ export class PlaceholderCommon extends React.Compone ) { let result; /** [SXA] it needs for deleting dynamics placeholder when we set him number(props.name) of container. - from backend side we get common name of placeholder is called 'container-{*}' where '{*}' marker for replacing **/ - if (rendering && rendering.placeholders && rendering.placeholders[PREFIX_PLACEHOLDER]) { - rendering.placeholders[name] = rendering.placeholders[PREFIX_PLACEHOLDER]; - delete rendering.placeholders[PREFIX_PLACEHOLDER]; + from backend side we get common name of placeholder is called 'nameOfContainer-{*}' where '{*}' marker for replacing **/ + if (rendering?.placeholders) { + Object.keys(rendering.placeholders).forEach((placeholder) => { + if (placeholder.indexOf('{*}') !== -1) { + rendering.placeholders[name] = rendering.placeholders[placeholder]; + delete rendering.placeholders[placeholder]; + } + }); } if (rendering && rendering.placeholders && Object.keys(rendering.placeholders).length > 0) { diff --git a/packages/sitecore-jss-react/src/test-data/non-ee-data.ts b/packages/sitecore-jss-react/src/test-data/non-ee-data.ts index d8a402501c..a1327b3bb3 100644 --- a/packages/sitecore-jss-react/src/test-data/non-ee-data.ts +++ b/packages/sitecore-jss-react/src/test-data/non-ee-data.ts @@ -245,7 +245,7 @@ export const sxaRenderingVariantDataWithoutCommonContainerName = { }, }, placeholders: { - 'no-container-{*}': [ + 'no-container': [ { uid: 'c4d5d43b-5aa8-4e03-8f16-9428f3e02d5c', componentName: 'RichText',