New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'web') #2371
Comments
I'm also facing the same issue when switched to Edit mode, for now, when creating sp object, checking null for this.context, resolving the issue, but this might fail for msgraph calls. |
@cwdata and @sallaadithya - have either of you tried the nightly build? The fix for the issue described in #2356 is not yet in a monthly release. |
I just came to know about Nightly build, but sorry, I can't try this now as our application is in production. Will try after the major release. |
@sallaadithya - sorry, a bit confused. How do you test your application before it hits production? You can drop the nightly build in there and test to see if this issue is resolved - just don't ship it live. If this fixes your issues, great, but if it doesn't, you'll need to wait another month before we can investigate. |
@patrick-rodgers |
The webpart on the page is not destroyed when placed in edit mode - rather the lifecycle is called again - so if the webpart or a service is holding a reference to the old context you would see this issue. Your code would need to account for the switch to edit mode. Your suggested edit would remove the caching of the _sp which is by design. Otherwise you can't call getSP when the context isn't present and is why it was coded that way. |
@patrick-rodgers, I think you misunderstood the problem here - seems I didn't explain it precisely enough. |
This issue is affecting me as well. Basically, the existing sp object isn't valid when the page is placed in edit mode. I've noticed that the behavior is the same though whether I am F5 refreshing the page in edit mode or toggling from display mode to edit mode. The workaround by removing the check to see if the sp object exists works though. If we still need to interrogate the sp object before creating a new one maybe there is a way to look at a specific property of the object to see if it needs to be recreated? I haven't tried 3.6.0 yet, but I could look into that as well. |
I have the same issue.. |
I can confirm that the sample should be changed to |
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. |
Category
Version
Please specify what version of the library you are using: [ 3.5.1 ]
Please specify what version(s) of SharePoint you are targeting: [ SPO ]
Observed Behavior
I recently ran into an issue similar to the one reported in #2239. For example, simply when switching the page on which the Webpart is placed into edit mode, the code in the componentDidMount() will error out when accessing getSP().web.(something).
After going through some debugging and trial and error steps I found a reason for that behavior.
In the example provided at https://pnp.github.io/pnpjs/concepts/project-preset/ -> Use a config file
the code is doing the following check
if (_sp === null && context != null) {
This leads to the problem described in the above mentioned issue (PnPJS is somehow not initialized properly).
The line needs to be changed to
if (context != null) {
After changing this line the problem disappeared. I'm not really deep into Javascript but it seems that the _sp object in the config file is still holding 'some' content which isn't valid anymore. The getSP(this.context) in the onInit() method of the Webpart isn't reinitializing the _sp object because it isn't null after a page navigation event -> Later usage of the object will lead to an error.
BTW: The example linked from the docs (https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-pnp-js-sample) is using the same problematic code.
Steps to Reproduce
From my point of view this should always happen when using the 'config file' from the docs, accessing getSP().web.(something) in componentDidMount() and changing the page into edit mode after the Webpart has loaded.
The text was updated successfully, but these errors were encountered: