'using getCurrentPage method on ngonInit loads the data but then returns null intermittently in Spartacus 4.2.0
I'm using cmsService from @spartacus/core to access all slots and components so that I can loop through page.slots to find a component based on its typeCode. the way compoennts are setup from commerce, we don't know what their UID is but we know about their typecode so need to look into page.slots array to find a component with a specific typecode. I am using below code to subscribe to getCurrentPage() in cmsService to get all slots.
ngOnInit(): void {
this.cmsService
.getCurrentPage()
.pipe(filter((page) => Boolean(page)))
.subscribe((page: Page) => {
//run a method to get component by typecode
}}
Problem: the above subscription returns data however sometimes it returns null intermittently.so if I'm on a page and refresh it, data might come and I can use it to populate my component with or data does come but then suddenly it turns to null. After page refresh, I can see that my component is getting populated for a sec and then it becomes empty because data turns to null. is there a way to fix above subscription or is there any other methos that can return a component based on its typecode?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
