Skip to content
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

Update to not fetch experience if it is empty #4149

Merged
merged 10 commits into from
Sep 25, 2023

Conversation

eastandwestwind
Copy link
Contributor

Closes #4147

Description Of Changes

Update to not fetch experience client-side if pre-fetched experience was empty. Empty simply means the location has no relevant experiences, so we shouldn't try to fetch the experience again client-side.

Code Changes

  • Update fides.ts to not fetch experience if it is empty
  • Update code comments for clarity

Steps to Confirm

  • Use a location with empty experience on a site with pre-fetch enabled
  • Confirm a client-side call to GET privacy-experience is NOT being made

Pre-Merge Checklist

@cypress
Copy link

cypress bot commented Sep 23, 2023

Passing run #4311 ↗︎

0 4 0 0 Flakiness 0
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

Merge 5797c6d into ad640cb...
Project: fides Commit: 91e399bb8c ℹ️
Status: Passed Duration: 00:57 💡
Started: Sep 24, 2023 1:03 AM Ended: Sep 24, 2023 1:04 AM

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

Copy link
Contributor

@NevilleS NevilleS left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@NevilleS NevilleS left a comment

Choose a reason for hiding this comment

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

Few nits but this is good thanks!

} else if (!isPrivacyExperience(experience)) {
// An empty experience (e.g. {}) is expected when 1. pre-fetch is enabled, and 2. the location has no associated
// experience. We should not fetch experiences again in this case. We only fetch experiences if it's undefined.
} else if (!experience) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit...

Suggested change
} else if (!experience) {
} else if (!effectiveExperience) {

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH, this was clearer before using the utils method. I reworked that method to suit your purpose

SteveDMurphy added a commit that referenced this pull request Sep 23, 2023
@NevilleS
Copy link
Contributor

@eastandwestwind I modified this to use the isPrivacyExperience helper, for consistency, since I do agree that y'all wanted it to work that way.

I also improved some test coverage to give us some confidence it behaves as expected 👍

@eastandwestwind eastandwestwind merged commit 6035252 into main Sep 25, 2023
10 checks passed
@eastandwestwind eastandwestwind deleted the 4147-dont-refetch-experience-if-empty branch September 25, 2023 14:04
eastandwestwind added a commit that referenced this pull request Sep 25, 2023
*
* This includes the special case where the input is an empty object ({}), which
* is a valid response when the API does not find a PrivacyExperience configured
* for the given geolocation.
*/
export const isPrivacyExperience = (
obj: PrivacyExperience | undefined | EmptyExperience
): obj is PrivacyExperience => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I happened to stumble on this PR and this change is a little dangerous type-wise—we claim that returning true means the obj passed in was of type PrivacyExperience, but this change makes it so it can be either PrivacyExperience or EmptyExperience. the type predicate will still say it's PrivacyExperience though!

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.

Fides.js caching for unsupported locations
3 participants