Skip to content

SPComponentLoader.loadScript SP.js breaks OOB controls #1117

@jpalo

Description

@jpalo

Category

  • Question
  • Typo
  • 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)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions