'Error on items.add in pnpjs after 30minutes

I´m using "@pnp/sp": "^3.0.3", I have this code

const sp = spfi().using(SPFx(props.context));
  const item = {
    Title: mail,
    URL: { Url: url.trim(), Description: name.trim() },
  };
  await sp.web.lists.getById(props.list).items.add(item);

It works, I can find the item in the list. It´s added.

If I have the page open 30 minutes and insert a new item it fails with this error

Error: Error making HttpClient request in queryable [403]  ::> {"odata.error":{"code":"-2130575252, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The security validation for this page is invalid and might be corrupted. Please use your web browser's Back button to try your operation again."}}}


Solution 1:[1]

It´s going to be solved in version 3.2.0 But doesn´t work with

const sp = spfi().using(SPFx(props.context));

It does with

import { spfi, SPBrowser } from "@pnp/sp";
....
const sp = spfi().using(
SPBrowser({
  baseUrl: props.context.pageContext.web.absoluteUrl,
}));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1