This bug was created as discussed in these issues: #5075 and #6201
In short: Theme provider functions do not seem to work when page is hosted as "single page web part" app.
The tutorial for using themes in the app: on https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/guidance/supporting-section-backgrounds does not work when the web part is hosted as "single page app".
If you follow the above tutorial and host a web part as a single-page-app, the theme provider returns undefined and the theme events are not fired.
I have created a sample project and put steps to reproduce the issue with theme below.
It has these settings in web part config:
"supportedHosts": ["SharePointWebPart", "SharePointFullPage"],
"supportsFullBleed": true,
"supportsThemeVariants": true,
The example can be found here (it is a stock HelloWorld web part generated with yeoman with these specified settings)
https://github.com/nbelyh/spfx-theme-issue
The important changes from the stock "HelloWorld" web part are highlighted:
To reproduce:
npm install
gulp bundle --ship
gulp package-solution --ship
This should produce .spfx package.
create (modern) SharePoint team site (as single-page apps can't be tested with workbench)
Upload the built .spfx solution to the site app catalog, and deploy for this site.
Add the .spfx app for the site (open home page, click New > Apps, then select "from your organization" then app
uploaded (spfx-issue-client-side-solution)
Go to site home page, click New > Page > App and select the upload app ("HelloWorld". This should produce a single-app page.
Save the page.
Open the Dev Tools console and check the messages. It should report what _tryGetTheme() returns. The result is expected to be not undefined. Now the log produces:
```
_themeProvider.tryGetTheme returned undefined
````
Please note that if you use the HelloWorld in a regular page, all events and tryGetTheme work as expected.
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
We are working on a fix. It appears that the single page app host does not instantiate ThemeProvider with the global theme.
Most helpful comment
We are working on a fix. It appears that the single page app host does not instantiate
ThemeProviderwith the global theme.