Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Angular][XMC] Ensure context is available at the time of placeholder rendering #1947

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Our versioning strategy is as follows:
* `[sitecore-jss-nextjs]` `[sitecore-jss]` Resolved an issue with Netlify where URL query parameters were being sorted, causing redirect failures. Added a method to generate all possible permutations of query parameters, ensuring proper matching with URL patterns regardless of their order. ([#1935](https://github.com/Sitecore/jss/pull/1935))
* `[sitecore-jss-angular]` Fix default empty field components to not render the unwanted wrapping tags ([#1937](https://github.com/Sitecore/jss/pull/1937)) ([#1940](https://github.com/Sitecore/jss/pull/1940))
* `[sitecore-jss-angular]` Fix image field style property not rendered properly ([#1944](https://github.com/Sitecore/jss/pull/1944))
* `[sitecore-jss-angular]` Fix nested dynamic placeholders not being displayed in Pages ([#1947](https://github.com/Sitecore/jss/pull/1947))
art-alexeyenko marked this conversation as resolved.
Show resolved Hide resolved

### 🎉 New Features & Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1269,4 +1269,20 @@ describe('Placeholder Metadata: dynamic placeholder:', () => {
expect(cleanedRenderedHTML).toEqual(expectedHTML);
})
);

fit(
art-alexeyenko marked this conversation as resolved.
Show resolved Hide resolved
'should retain correct name of dynamic placeholder',
waitForAsync(async () => {
const layoutData = layoutDataForNestedDynamicPlaceholder('container-{*}');
const component = layoutData.sitecore.route;
const phKey = 'container-2';
comp.name = phKey;
comp.rendering = (component as unknown) as ComponentRendering;

fixture.detectChanges();
await fixture.whenStable();
const placeholder = de.query(By.css('sc-placeholder')).componentInstance;
expect(Object.keys(placeholder?.rendering?.placeholders || [])).toEqual(['container-{*}']);
})
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ export class PlaceholderComponent implements OnInit, OnChanges, DoCheck, OnDestr
private placeholderData?: (ComponentRendering<ComponentFields> | HtmlElementRendering)[];
private destroyed = false;
private parentStyleAttribute = '';
private editMode?: EditMode = undefined;
private contextSubscription: Subscription;

constructor(
Expand All @@ -145,7 +144,11 @@ export class PlaceholderComponent implements OnInit, OnChanges, DoCheck, OnDestr
// eslint-disable-next-line @typescript-eslint/ban-types
@Inject(PLATFORM_ID) private platformId: Object,
private jssState: JssStateService
) {}
) {
this.contextSubscription = this.jssState.state.subscribe(({ sitecore }) => {
this.metadataMode = sitecore?.context.editMode === EditMode.Metadata;
art-alexeyenko marked this conversation as resolved.
Show resolved Hide resolved
});
}

@Input()
set inputs(value: { [key: string]: unknown }) {
Expand All @@ -170,10 +173,6 @@ export class PlaceholderComponent implements OnInit, OnChanges, DoCheck, OnDestr
}
}
this.placeholderData = this.renderings || this.getPlaceholder() || [];
this.contextSubscription = this.jssState.state.subscribe(({ sitecore }) => {
this.editMode = sitecore?.context.editMode;
this.metadataMode = this.editMode === EditMode.Metadata;
});
}

ngOnDestroy() {
Expand Down Expand Up @@ -267,7 +266,7 @@ export class PlaceholderComponent implements OnInit, OnChanges, DoCheck, OnDestr
? getDynamicPlaceholderPattern(placeholder)
: null;
if (patternPlaceholder && patternPlaceholder.test(phName)) {
if (this.editMode === EditMode.Metadata) {
if (this.metadataMode) {
phName = placeholder;
} else {
this.rendering.placeholders![phName] = this.rendering.placeholders![placeholder];
Expand Down