sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

SPComponentLoader.loadScript SP.js breaks OOB controls

Open jpalo opened this issue 8 years ago • 7 comments

Category

  • [ ] Question
  • [ ] Typo
  • [x] Bug
  • [ ] Additional article idea

Expected or Desired Behavior

I would be able to load SP related JS files and OOB SP UI components such as search would work.

Observed Behavior

After adding SPFx web part to page, certain OOB controls stop working. E.g., search box throws errors when it gets focus, ribbon buttons are disabled/non-functioning.

Steps to Reproduce

  1. Create simple SPFx web part without JS framework
  2. In main .ts file's render(), load JSOM related files like this
if(!window["SP"] || !window["SP"]["ClientContext"]) {
	SPComponentLoader.loadScript("/_layouts/15/init.js", {
		globalExportsName: "$_global_init"
	}).catch((error) => {
		console.log("/_layouts/15/init.js error");
	}).then((): Promise<{}> => {
		return SPComponentLoader.loadScript("/_layouts/15/MicrosoftAjax.js", {
		globalExportsName: "Sys"
		});
	}).catch((error) => {
		console.log("/_layouts/15/MicrosoftAjax.js error");
	}).then((): Promise<{}> => {
		return SPComponentLoader.loadScript("/_layouts/15/SP.Runtime.js", {
		globalExportsName: "SP"
		});
	}).catch((error) => {
		console.log("/_layouts/15/SP.Runtime.js error");
	}).then((): Promise<{}> => {
		return SPComponentLoader.loadScript("/_layouts/15/SP.js", {
		globalExportsName: "SP"
		});
	}).catch((error) => {
		console.log("/_layouts/15/SP.js error");
	}).then((): void => {
		this._renderListAsync(true);
	});
}
  1. Deploy JS to SPO
  2. Add web part to page (default Seattle.master)
  3. Refresh page
  4. Click on search field on top right, in JS console there are errors:
Uncaught TypeError: Cannot read property 'hidePrompt' of null
    at SodCallbackInfo.eval [as success] (default.aspx:502)
    at c (VM54849 init.js:1)
    at b (VM54849 init.js:1)
    at NotifyOnLoad (VM54849 init.js:1)
    at VM54849 init.js:1
    at HTMLScriptElement.<anonymous> (init.js:1)

and

Uncaught RangeError: Maximum call stack size exceeded
    at ULSSendExceptionImpl (https://mytenant.sharepoint.com/_layouts/15/init.js:1:105308)
    at ULSOnError (https://static.sharepointonline.com/bld/_layouts/15/16.0.7129.1205/init.js:1:105898)
    at ULSObject.SupplementDefaultMethod.window.(anonymous function) [as OriginalOnError] (https://static.sharepointonline.com/bld/_layouts/15/16.0.7129.1205/init.js:1:178439)
    at ULSSendExceptionImpl (https://mytenant.sharepoint.com/_layouts/15/init.js:1:105827)
    at ULSOnError (https://static.sharepointonline.com/bld/_layouts/15/16.0.7129.1205/init.js:1:105898)
    at ULSObject.SupplementDefaultMethod.window.(anonymous function) [as OriginalOnError] (https://static.sharepointonline.com/bld/_layouts/15/16.0.7129.1205/init.js:1:178439)
    at ULSSendExceptionImpl (https://mytenant.sharepoint.com/_layouts/15/init.js:1:105827)
    at ULSOnError (https://static.sharepointonline.com/bld/_layouts/15/16.0.7129.1205/init.js:1:105898)
    at ULSObject.SupplementDefaultMethod.window.(anonymous function) [as OriginalOnError] (https://static.sharepointonline.com/bld/_layouts/15/16.0.7129.1205/init.js:1:178439)
    at ULSSendExceptionImpl (https://mytenant.sharepoint.com/_layouts/15/init.js:1:105827)

jpalo avatar Dec 07 '17 12:12 jpalo

@jpalo - THanks for your feedback. It looks like you should try to do what you are doing by following the article at: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/guidance/connect-to-sharepoint-using-jsom

If your issue still reproes please open a new issue saying you are using the methods in the documentation and it is still having problems.

GrahamMcMynn avatar Dec 12 '17 17:12 GrahamMcMynn

#facepalm

jpalo avatar Dec 12 '17 18:12 jpalo

Great close an issue that is not fixed by adding a link that adds no value at all... I also get this error, the link mcmynn83 is pointing to is using the same code (apart from the catch statements).

@jpalo Did you manage to fix this?

Denloof avatar Jan 25 '18 16:01 Denloof

@Denloof @jpalo - sorry, it does look like it is the same code. My mistake.

GrahamMcMynn avatar Jan 25 '18 17:01 GrahamMcMynn

A similar issue related to loadScript was fixed by end of January, and this one doesn't reproduce anymore with the current bits. I am closing this issue, but feel free to re-open if that still happens to you.

mpasarin avatar Feb 15 '18 23:02 mpasarin

I am getting the same behavior as in the original issue. I added a web part that loads the SP.js and SP.taxonomy.js files. I added the web part to the search center page. I get the same error messages ("Cannot read property 'hidePrompt' of null" and "Uncaught RangeError: Maximum call stack size exceeded") when the OOB searchbox get focus. Also writing in the searchbox is quite slow and raises my laptops CPU usage to >70% for a few seconds. By slow I mean that the text appears ~5 seconds after typing. Is there something I could try to do to fix this?

jesseve avatar Nov 02 '18 14:11 jesseve

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

msft-github-bot avatar Jan 28 '20 18:01 msft-github-bot