“Cannot Read Property ‘STS’ of Undefined” When Using SP.UI.ModalDialog in SharePoint 2013
I’m using SharePoint’s built-in modal dialog for a single page application I’ve been developing. When I refresh the page to test changes I’ll randomly get an error saying that “Cannot read property ‘STS’ of undefined.” I’m using the Script-on-demand functions that should make things work:
SP.SOD.executeFunc('sp.ui.dialog.js', 'SP.UI.ModalDialog', myFunction);
Looking at the stack trace, I can see that sp.ui.dialog.js is using the
window.self.Strings object which is throwing the error.
This variable is created by the strings.js file, which seems to be loading after the sp.ui.dialog.js file when this happens even though it is part of the dependency chain for sp.ui.dialog.js. Everything works OK if I force a hard refresh, but when the HTTP request for sp.ui.dialog.js returns a 304 Not Modified response that’s when the error happens.
To get around this race condition, I followed a suggestion from a StackExchange answer and loaded the strings.js file explicitly with
SP.SOD.loadMultiple(['strings.js', 'sp.ui.dialog.js'], myFunction);
Now I don’t have the error any more. This may be fixed in a more recent patch for SharePoint 2013 (our environment at my company is a few patches behind), but so far this solution has worked reliably. Is anyone else having this issue?