Skip to content

Refactor init for better clarity + TCF separation#6173

Merged
gilluminate merged 3 commits intomainfrom
gill/refactor-fides-init
May 29, 2025
Merged

Refactor init for better clarity + TCF separation#6173
gilluminate merged 3 commits intomainfrom
gill/refactor-fides-init

Conversation

@gilluminate
Copy link
Copy Markdown
Contributor

@gilluminate gilluminate commented May 27, 2025

Description Of Changes

There was some developer confusion around when and how existing consent gets set and how it fits in to the initialization process. This refactor is meant to clear up confusion by moving some of the logic to the main init thread. There's a different set of logic needed for regular fides vs. TCF vs. Headless, and this refactor helps make that clear without changing any of the existing functionality.

Code Changes

  • Rename getInitialFides to getInitialFidesFromConsentCookie for clarity
  • Add lots of extra comments explaining why things are the way they are
  • Move the checks for existing cookie, TCF string, and Migratable consent (3rd party cookies) up to the main init thread rather than burying it in getInitialFidesFromConsent where that context isn't obvious and can be confusing.

Steps to Confirm

  1. No change in functionality, so general smoke tests and passing CI tests are warranted.

Pre-Merge Checklist

  • Issue requirements met
  • All CI pipelines succeeded
  • CHANGELOG.md updated
    • Add a db-migration This indicates that a change includes a database migration label to the entry if your change includes a DB migration
    • Add a high-risk This issue suggests changes that have a high-probability of breaking existing code label to the entry if your change includes a high-risk change (i.e. potential for performance impact or unexpected regression) that should be flagged
    • Updates unreleased work already in Changelog, no new entry necessary
  • Followup issues:
    • Followup issues created
    • No followup issues
  • Database migrations:
    • Ensure that your downrev is up to date with the latest revision on main
    • Ensure that your downgrade() migration is correct and works
      • If a downgrade migration is not possible for this change, please call this out in the PR description!
    • No migrations
  • Documentation:
    • Documentation complete, PR opened in fidesdocs
    • Documentation issue created in fidesdocs
    • If there are any new client scopes created as part of the pull request, remember to update public-facing documentation that references our scope registry
    • No documentation updates required

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
fides-plus-nightly ⬜️ Ignored (Inspect) Visit Preview May 29, 2025 4:06pm
fides-privacy-center ⬜️ Ignored (Inspect) May 29, 2025 4:06pm

@gilluminate gilluminate force-pushed the gill/refactor-fides-init branch 3 times, most recently from b24cff7 to 9a95077 Compare May 28, 2025 17:24
Copy link
Copy Markdown
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.

I think I'm following this, and from code inspection I see that the logic is intact.

Comment on lines -166 to -171
// Register any configured consent migration providers
registerDefaultProviders(options);

// Check if there's consent available to migrate from any provider
const { consent: migratedConsent } = readConsentFromAnyProvider(options);
const hasMigratableConsent = !!migratedConsent;
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.

Were we doing this part twice before (registerDefaultProviders and readConsentFromAnyProvider)? Seems like it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yep! ...and only so we could form the if statement.

Comment thread clients/fides-js/src/lib/initialize.ts Outdated
Comment thread clients/fides-js/src/fides.ts Outdated
Comment on lines +151 to +160
this.experience = config.experience; // pre-fetched experience if available
const hasExistingCookie = !isNewFidesCookie(this.cookie);
const hasMigratableConsent = !!migratedConsent;
if (hasExistingCookie || hasMigratableConsent) {
/*
* We have enough information to initialize the Fides object before we have a valid experience.
* In this case, the experience is less important because the user has already consented to something.
* The earlier we can communicate consent to the vendor, the better.
*/
const initialFides = getInitialFidesFromConsent({
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.

OK, yeah, this is clearer; basically you've hoisted the internal if out of the getInitialFides code and placed it here.

@gilluminate gilluminate force-pushed the gill/refactor-fides-init branch from de56a0d to 9120021 Compare May 29, 2025 16:06
@gilluminate gilluminate merged commit 0955fb3 into main May 29, 2025
17 checks passed
@gilluminate gilluminate deleted the gill/refactor-fides-init branch May 29, 2025 16:10
@cypress
Copy link
Copy Markdown

cypress Bot commented May 29, 2025

fides    Run #12946

Run Properties:  status check passed Passed #12946  •  git commit 0955fb33c1: Refactor init for better clarity + TCF separation (#6173)
Project fides
Branch Review main
Run status status check passed Passed #12946
Run duration 00m 53s
Commit git commit 0955fb33c1: Refactor init for better clarity + TCF separation (#6173)
Committer Jason Gill
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 5
View all changes introduced in this branch ↗︎

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.

2 participants