Skip to content

feat: expose cache entry on shouldUpdateScript#1319

Open
ElielC wants to merge 2 commits intocallstack:mainfrom
ElielC:main
Open

feat: expose cache entry on shouldUpdateScript#1319
ElielC wants to merge 2 commits intocallstack:mainfrom
ElielC:main

Conversation

@ElielC
Copy link
Copy Markdown

@ElielC ElielC commented Dec 9, 2025

Summary

Exposes a new property on locator.shouldUpdateScript in order to enable more custom caching behaviors on afterResolve hooks, following this discussion

Test plan

Ensure all tests pass and there are no regression issues

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Dec 9, 2025

🦋 Changeset detected

Latest commit: 864bb7b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@callstack/repack Major
@callstack/repack-plugin-expo-modules Major
@callstack/repack-plugin-nativewind Major
@callstack/repack-plugin-reanimated Major
@callstack/repack-dev-server Major
@callstack/repack-init Major

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

@vercel
Copy link
Copy Markdown

vercel Bot commented Dec 9, 2025

@ElielC is attempting to deploy a commit to the Callstack Team on Vercel.

A member of the Team first needs to authorize it.

@dannyhw
Copy link
Copy Markdown
Collaborator

dannyhw commented Dec 9, 2025

Nice one @ElielC 🙌

@ElielC
Copy link
Copy Markdown
Author

ElielC commented Dec 10, 2025

The changeset bot references the release as a Major, but i created the changeset as a Minor release, is that right?

@dannyhw
Copy link
Copy Markdown
Collaborator

dannyhw commented Dec 10, 2025

Thats strange, @jbroma is this a bug with the changesets bot?

@jbroma
Copy link
Copy Markdown
Contributor

jbroma commented Jan 15, 2026

The changeset bot references the release as a Major, but i created the changeset as a Minor release, is that right?

hey, sorry for lack of activity lately, changesets can always be adjusted manually before the release so no need to worry about that

Copy link
Copy Markdown
Contributor

@MikitasK MikitasK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall, these changes looks good to me 👍 also core behavior works as expected on my side ☑️
just a few minor comments:

Comment on lines +283 to +291
// 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
);
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code assumes cachedData always exists, but it might be undefined on first load. so let's guard no-cache case before dereferencing cachedData

Suggested change
// 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
);
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d also suggest adding a unit test covering for these cases:

  • cachedData === undefined on first load
  • cachedData populated on subsequent load
  • changed locator making isScriptCacheOutdated === true

Comment on lines +508 to +509
script.shouldUpdateCache(this.cache[cacheKey]),
this.cache[cacheKey]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
script.shouldUpdateCache(this.cache[cacheKey]),
this.cache[cacheKey]
script.shouldUpdateCache(this.cache[cacheKey]),
this.cache[cacheKey] ? { ...this.cache[cacheKey] } : undefined

@bartekkrok
Copy link
Copy Markdown
Contributor

This looks like a solid addition!

Could you add a test case that specifically covers this scenario ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants