Custom Web Part Disappears

Copper Contributor

I recently created a custom web part and deployed it to our SharePoint online site. I can add the part to a Site Page with no problems, it saves and publishes with no errors. Everything works as expected until you navigate away from the page. When the page opens again the web part is gone. If you edit the page you can see that there is an empty web part where the custom one should be. I get the same result from adding the part to an existing section as I do when I give it it's own section. I've tried rebuilding the part, changing the version number, deleting and re-adding and creating a version that consists of just the word "Test" all with the same results. I haven't found anything online so I'm hoping someone here can let me know what I'm missing.

10 Replies

Hey Daniel can be a multitude of things.  My first stop would be the Chrome developer tools... reload the page and look for any errors that may be related to your custom web part.  It may be a resource file isn't found, it may be permissions, it may be a missing semi-colon :)  Good luck!

Thanks for the suggestions!

 

I double checked the console but still don't see anything relevant. Chrome shows no errors, some depreciated property warning and some non-registered setting warnings, none of which appear related to the web part. The only error I see on the page is when running it in Safari which throws a 404 error for ActivityMonitor.js.map as well as the same warnings I see in Chrome. All of these errors and warnings show up on pages without the web part and on other sites in our tenant.

 

 

I'm not seeing anything that would indicate, to me at least, that there is a permission issue or missing resource. The part works as expected after adding it to the page - it's pretty simple and has three options that can be toggled on and off (one inserts a JavaScript and the other two insert CSS styles) and a full-width red div so I can see that it's actually there. I can save drafts, publish and edit the page and change the web part settings. I get the depreciated warnings on publish and edit but no errors. If I view the page in a different tab or browser the web part is not shown. However, if I come back to the original page (left open after publishing) the part is still there, if I edit the page it's still there and works normally. Refreshing the page or navigating away and back will make it disappear with no new warnings or errors. It doesn't appear to matter if the options are on or off.

 

I don't see any errors in Visual Studio Code and all of the semi-colons (as well as commas which I have a bad habit of forgetting in property lists when I'm in a hurry) appear to be where they should be.

This might be too simple of a question but I'll ask it in case this is a new SP Online instance and your first time hitting this issue... But did you check the SharePoint settings out in Office 365 to ensure Custom Scripting is enabled? It's a dumb question but I've had "memory lapses" where this was the simple answer to other similar painful problems. If it is disabled, enable it and it will take up to 24 hours to take effect.

Thanks. I've run the enable command and will give it another try tomorrow.

I tried it again this afternoon and had a moment of hope. I was able to navigate away from the page then back again and it was still there. Unfortunately, when I tried to open it in another tab the part disappeared again. Refreshing the page causes it to disappear as well so it may have just been showing due to browser caching.

What kind of web part is it?  A content editor web part with code directly in it or something else?

I'm afraid that I don't quite understand your question. This is the first web part I've built and I don't recall there being any other type information beyond "WebPart" when I set it up.

 

It inserts a div with a single line of text and some basic CSS styling and has three components that can be toggled on and off; one JavaScript and two CSS styles.

@Daniel Lyons III I am facing the same issue. Is there any solution? 

You guys ever figure this out? I’ve got the same thing happening to me. Renders fine when I add it, but if I refresh the page it’s gone.

@Fangliang Pan @Perry Armiras 

 

If I remember correctly, the solution was to enable the Office 365 CDN to host the web parts.