Branding Application Extension sometimes loads before Placeholder's are in DOM
Category
- [ ] Question
- [ ] Typo
- [*] Bug
- [ ] Additional article idea
Observed Behavior
Occasionally we are seeing our branding extension fail to load due to the Top/Bottom placeholders not being present in the DOM yet. Not sure why this happens, I would expect these to always be present by the time the extension is loaded.
Steps to Reproduce
This doesn't happen regularly, and we have worked around it by adding this (its dirty but maybe something similar can be integrated in to future releases in to tryCreateContent):
if(document.querySelectorAll("[data-sp-placeholder='Top']").length == 0)
{
window.setTimeout(() => this.onInit(),50);
return;
}
https://github.com/SharePoint/sp-dev-docs/issues/2773
Did you have tried the solution that @dgusoff commented?
The correct solution to this is to hook onto the placeholders in your placeholderProvider.changedEvent handler. This even will fire when the placeholders are created, and any time they change. The sample code in this tutorial (https://docs.microsoft.com/en-us/sharepoint/dev/spfx/extensions/get-started/using-page-placeholder-with-extensions) does the right thing (as well as the wrong thing. Pull request made to clarify it)
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues