require.js and listviewdataprefetch.js of SharePoint removes styles of Office UI Fabric
Bug Report
- Package version(s): 4.35.1
- Browser and OS versions: All browsers, Windows 10, ...
Requested priority: Blocking
Products/sites affected: All SP Online classic pages on tenants with the require.js version below which are using Office UI Fabric components.
Describe the issue:
We still got the problem on our tenant that our styles get removed when the page is loaded (mostly with clear cache)
require.js version: https://spoprod-a.akamaihd.net/files/odsp-next-prod_ship-2017-09-08-sts_20170920.006/require-951f856e.js
For example we use the Facepile component to display Users but sometimes the css got removed, always when require.js and listviewdataprefetch.js are loaded.
Any suggestions what we have to do? Thanks in advance!
Actual behavior:

Expected behavior:

Steps to reproduce:
- Open any browser
- Clear Cache and require.js include listviewdataprefetch.js gets loaded
- CSS for components is missing completely
@jijizz Can you please take a look?
It seems this has regressed again.
sure, I have couple questions:
- did this issue only start happening with most recent build?
- @db3005 Can you please share a repro page? A test account that I can login to debug would be the best because I can not reproduce by myself.
Hey @jijizz ,
this issue happened with nearly every build version we tested, i created a new app with office ui version 4.50.1, which only renders a rating component with 3 stars, but the CSS is broken sometimes. This only happens if the require.js gets loaded, this is mostly after clear cache, otherwise the layout is correct if it doesnt get loaded.
I created a repro page with this little app, can u send me an email ?
Thanks in advance
@db3005, email sent, waiting for the repro information. Thanks
@jijizz, email with repro information sent, thanks for your help!
Thanks for the repro. For this particular case, it is caused by the interference between your Office UI bundle (main.js) and a modern document library UI performance feature. That performance feature overloads loadStyles function before being used by your office UI bundle. To easily workaround it, please add this line of code before loading your office ui fabric react bundle:
window.__themeState__.loadStyles = undefined;
So your bundle loading code should be something like this:
document.getElementById("buttonTest").onclick = function() {
window.__themeState__.loadStyles = undefined;
var script = document.createElement("script"); //Make a script DOM node
script.src = "https://<your cdn>/xxxx/xxxx/main.js";
document.head.appendChild(script);
}
Thanks for your fast feedback!
In this case that we click a button and the react stuff gets loaded it will work with your workaround. But in many other cases we start loading the react files on page load and then it will happen the same issue. I changed the repro that the javascript load the react files on page load:
if (window.__themeState__ !== undefined) {
window.__themeState__.loadStyles = undefined;
}
var script = document.createElement("script");
script.src = "main.js";
document.head.appendChild(script);
Still the same issue :-( Any other workaround with this problem ?
Thanks and best regards
Yeah, it is a nasty race condition. for your case, add the highlighted code before your script loading code:
window.__themeState__ = window.__themeState__ || {
theme: undefined,
lastStyleElement: undefined,
registeredStyles: [],
loadStyles: undefined
};
var script = document.createElement("script");
script.src = "main.js";
document.head.appendChild(script);
I understand the code looks a bit hacky this way. But you should be unblocked. Meanwhile, I am seeking a fix in sharepoint code base.
Thanks for your workaround. I included it now without the "window.themeState ||" so that the themeState Object is always set to
{
theme: undefined,
lastStyleElement: undefined,
registeredStyles: [],
loadStyles: undefined
};
when the React gets loaded. Now it always renders correct, but another fix in the sharepoint code if possible would be ofcourse much better.
Thanks for your help so far!
Closing as this seems to have been resolved.