pnpjs icon indicating copy to clipboard operation
pnpjs copied to clipboard

Moderpage on Save/Publish loosing all the sections and webparts.

Open pavan2920 opened this issue 8 years ago • 6 comments

Hi Team,

I am trying to update the SharePoint modern page. For the Very first time when ever the site is created, when i try to get the page object and just save and publish the page looses all the controls/sections and webparts on it.

Below is the code which i am using in my solution.

const mySP = sp.configure({
                    cache: "default"
                }, this.props.webPartContext.pageContext.web.absoluteUrl);
const page: ClientSidePage = await ClientSidePage.fromFile(mySP.web.getFileByServerRelativeUrl(this.props.webPartContext.pageContext.web.serverRelativeUrl + "/" + WelcomePageURL["WelcomePage"]));
await page.save();
page.publish();

Also one more observation, when i edit and publish page manually by going to site then run the above code then nothing will be lost.

Could you please help me with with any suggestion/solution.

Thanks & Regards, Pavan Nesargi.

pavan2920 avatar Sep 07 '18 09:09 pavan2920

I just tried the following code in the SPEditor (Chrome extension) console, in my SharePoint dev tenant. I have an instance of "SharePoint starter kit" deployed and I tried to access the Personal.aspx, save it and publish. This worked splendid.

import { sp, ClientSidePage } from "@pnp/sp";

(async () => {

const file = sp.web.getFileByServerRelativeUrl('/sites/tmportal/SitePages/Personal.aspx');
const page = await ClientSidePage.fromFile(pageFile);
await page.save();
await page.publish();
})().then(_ => console.log('Yay')).catch(console.log);

simonagren avatar Sep 07 '18 18:09 simonagren

@simonagren , thanks for the reply. Yes custom page its working as expected but he Landing page(Welcome page) which is Home.aspx, once the site is created if you try the above code with that page then all the WP will be removed form the page.

FYI image

Only for the first time, if you Edit and publish(Manually/grammatically) and then again try the above things it works as expected.

pavan2920 avatar Sep 10 '18 06:09 pavan2920

@pavan2920 @patrick-rodgers this is a bug in SharePoint as far as I can tell. It's not a PnPJS bug.

When you create a new teamsite and try to access the "welcome page" via rest, either via PnPJS or just "rest": /_api/web/getFileByServerRelativeUrl('/sites/test2/sitepages/home.aspx')/listItemAllFields?$select=CanvasContent1,CommentsDisabled You don't get the sections and the webparts included. So when you try to save and publish via rest, you save an empty page really.

image

ONLY after an Manual edit and publish of the page, the same restcall gets the sections etc.

image

simonagren avatar Sep 12 '18 06:09 simonagren

Thanks @simonagren - there is some weirdness with the welcome page in sites.

patrick-rodgers avatar Sep 14 '18 00:09 patrick-rodgers

@patrick-rodgers @patmill commented it here:

https://github.com/SharePoint/sp-dev-docs/issues/2527#issuecomment-421155147

simonagren avatar Sep 14 '18 04:09 simonagren

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.

github-actions[bot] avatar Apr 20 '21 20:04 github-actions[bot]