feat: expose cache entry on shouldUpdateScript#1319
feat: expose cache entry on shouldUpdateScript#1319ElielC wants to merge 2 commits intocallstack:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 864bb7b The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@ElielC is attempting to deploy a commit to the Callstack Team on Vercel. A member of the Team first needs to authorize it. |
|
Nice one @ElielC 🙌 |
|
The changeset bot references the release as a Major, but i created the changeset as a Minor release, is that right? |
|
Thats strange, @jbroma is this a bug with the changesets bot? |
hey, sorry for lack of activity lately, changesets can always be adjusted manually before the release so no need to worry about that |
MikitasK
left a comment
There was a problem hiding this comment.
overall, these changes looks good to me 👍 also core behavior works as expected on my side ☑️
just a few minor comments:
| // Custom logic to determine if the script should be updated | ||
| return ( | ||
| cachedData.method !== locator.method || | ||
| cachedData.url !== locator.url || | ||
| cachedData.query !== locator.query || | ||
| !shallowEqual(cachedData.headers, locator.headers) || | ||
| cachedData.body !== locator.body | ||
| ); | ||
| }; |
There was a problem hiding this comment.
This code assumes cachedData always exists, but it might be undefined on first load. so let's guard no-cache case before dereferencing cachedData
| // Custom logic to determine if the script should be updated | |
| return ( | |
| cachedData.method !== locator.method || | |
| cachedData.url !== locator.url || | |
| cachedData.query !== locator.query || | |
| !shallowEqual(cachedData.headers, locator.headers) || | |
| cachedData.body !== locator.body | |
| ); | |
| }; | |
| // Custom logic to determine if the script should be updated | |
| if (!cachedData) return true; | |
| return ( | |
| cachedData.method !== locator.method || | |
| cachedData.url !== locator.url || | |
| cachedData.query !== locator.query || | |
| !shallowEqual(cachedData.headers, locator.headers) || | |
| cachedData.body !== locator.body | |
| ); | |
| }; |
There was a problem hiding this comment.
I’d also suggest adding a unit test covering for these cases:
cachedData === undefinedon first loadcachedDatapopulated on subsequent load- changed locator making
isScriptCacheOutdated === true
| script.shouldUpdateCache(this.cache[cacheKey]), | ||
| this.cache[cacheKey] |
There was a problem hiding this comment.
passing this.cache[cacheKey] directly into shouldUpdateScript implies that users receive the actual cached object, not a defensive copy. which means that Re.Pack’s internal cache entry might be affected If user's code mutates cachedData. so, I'd prefer to pass it in more safer way:
| script.shouldUpdateCache(this.cache[cacheKey]), | |
| this.cache[cacheKey] | |
| script.shouldUpdateCache(this.cache[cacheKey]), | |
| this.cache[cacheKey] ? { ...this.cache[cacheKey] } : undefined |
|
This looks like a solid addition! Could you add a test case that specifically covers this scenario ? |
Summary
Exposes a new property on
locator.shouldUpdateScriptin order to enable more custom caching behaviors onafterResolvehooks, following this discussionTest plan
Ensure all tests pass and there are no regression issues