web info cleanup #8
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
problem
Functions in
src/utils/sharepoint.rest/web.ts
are tightly coupled, lack explicit responsibilities, and call each other circularly which is hard to follow and reason with.Call stack graph generated with
Code2Flow
("module": "es2020"
,splines="ortho"; deleted
) of the unchanged code:GetJsonSync
can call various other functions in this call graph throughgetFormDigest
duringPOST
requests. However, since all requests in these functions areGET
requests, I have omitted this call edge.core URL resolution logic
(
GetSiteUrl
&GetFileSiteUrl
&GetRestBaseUrl
)hasGlobalContext
->_spPageContextInfo.webServerRelativeUrl
window.location.pathname
.ServerRelativeUrl
core WebInfo resolution logic
(
GetWebInfo
&GetWebInfoSync
)GET
request using/_api/site/openWebById('{ID}')?$Select={...WEB_INFO}
GET
request using/_api/web?$Select={...WEB_INFO}
core WebId resolution logic
(
GetWebId
&GetWebIdSync
)GET
request using/_api/web/Id
proposed changes
There are 2 circular call stacks present. The changes proposed do not (should not?) change ANY exported function behaviour.
GetSiteUrl > GetWebInfoSync > GetSiteUrl
. Here, ifGetSiteUrl
is given a GUID, it intentionally callsGetWebInfoSync
withsiteUrl = null
to trigger the "local" resolution of getting an initialsiteUrl
to make theGetWebInfoSync
call with. The proposed solution is to refactor the "local" resolution logic ofGetSiteUrl
intoGetSiteUrlLocally
. This way,GetSiteUrl
is given a clearer responsibility, and functions that want to resolve a siteUrl locally (possibly using a candidate URL, but NOT using a GUID) can callGetSiteUrlLocally
.GetSiteUrl > GetFileSiteUrl > GetWebIdSync > _getWebIdRequestUrl > GetRestBaseUrl > GetSiteUrl
. Here,GetFileSiteUrl
needs a url to perform its "brute force" check of its current url. It obtains that by traversing the call stack all the way toGetSiteUrl
which just returnsmakeServerRelativeUrl(normalizeUrl(<url>))
. The proposed solution is to keep its logic more contained in its function by simply callingmakeServerRelativeUrl(normalizeUrl(<url>))
directly, thus, not giving the impression thatGetSiteUrl
is performing some sort of circular magic.Note: There was also an infinite loop bug in
GetFileSiteUrl
that has been fixed, and a bug where the site file name may have been popped that was fixed.Call stack graph after changes: