Skip to content

Commit

Permalink
Apply any updated state to the overlay (#5384)
Browse files Browse the repository at this point in the history
  • Loading branch information
gilluminate authored Oct 16, 2024
1 parent 46cc415 commit 88a32f0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The types of changes are:
### Fixed
- Fixed a bug where D&D tables were rendering stale data [#5372](https://github.com/ethyca/fides/pull/5372)
- Fixed issue where Dataset with nested fields was unable to edit Categories [#5383](https://github.com/ethyca/fides/pull/5383)
- Fixed racecondition where GPC being updated after FidesJS initialization caused Privacy Notices to be in the wrong state [#5384](https://github.com/ethyca/fides/pull/5384)


## [2.47.0](https://github.com/ethyca/fidesplus/compare/2.46.2...2.47.0)
Expand Down
10 changes: 8 additions & 2 deletions clients/fides-js/src/components/notices/NoticeOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ConsentMethod,
FidesCookie,
Layer1ButtonOption,
NoticeConsent,
PrivacyNotice,
PrivacyNoticeTranslation,
PrivacyNoticeWithPreference,
Expand Down Expand Up @@ -58,7 +59,7 @@ const NoticeOverlay: FunctionComponent<OverlayProps> = ({

// TODO (PROD-1792): restore useMemo here but ensure that saved changes are respected
// eslint-disable-next-line react-hooks/exhaustive-deps
const initialEnabledNoticeKeys = () => {
const initialEnabledNoticeKeys = (consent?: NoticeConsent) => {
if (experience.privacy_notices) {
// ensure we have most up-to-date cookie vals
// TODO (PROD-1792): we should be able to replace parsedCookie with savedConsent
Expand All @@ -67,7 +68,7 @@ const NoticeOverlay: FunctionComponent<OverlayProps> = ({
const val = resolveConsentValue(
notice,
getConsentContext(),
parsedCookie?.consent,
consent || parsedCookie?.consent,
);
return val ? (notice.notice_key as PrivacyNotice["notice_key"]) : "";
});
Expand Down Expand Up @@ -124,6 +125,11 @@ const NoticeOverlay: FunctionComponent<OverlayProps> = ({
Array<string>
>(initialEnabledNoticeKeys());

window.addEventListener("FidesUpdating", (event) => {
// If GPC is being applied after initialization, we need to update the initial overlay to reflect the new state. This is especially important for Firefox browsers (Gecko) because GPC gets applied rather late due to how it handles queuing the `setTimeout` on the last step of our `initialize` function.
setDraftEnabledNoticeKeys(initialEnabledNoticeKeys(event.detail.consent));
});

const isAllNoticeOnly = privacyNoticeItems.every(
(n) => n.notice.consent_mechanism === ConsentMechanism.NOTICE_ONLY,
);
Expand Down
4 changes: 3 additions & 1 deletion clients/fides-js/src/lib/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ export const updateConsentPreferences = async ({
preference.consentPreference === UserConsentPreference.OPT_OUT,
)
.forEach((preference) => {
removeCookiesFromBrowser(preference.notice.cookies);
if (preference.notice?.cookies) {
removeCookiesFromBrowser(preference.notice.cookies);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,11 @@ const NoticeDrivenConsent = ({ base64Cookie }: { base64Cookie: boolean }) => {
noticePreference.notice
) {
// DEFER (PROD-2737) remove type casting
removeCookiesFromBrowser(
noticePreference.notice.cookies as FidesJSCookies[],
);
if (noticePreference.notice.cookies) {
removeCookiesFromBrowser(
noticePreference.notice.cookies as FidesJSCookies[],
);
}
}
});
router.push("/");
Expand Down
8 changes: 8 additions & 0 deletions clients/privacy-center/public/fides-js-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ <h2>Property id</h2>
} else {
window.addEventListener("FidesInitialized", onInitialized);
}
window.addEventListener("FidesUpdated", () => {
console.log("Fides has been updated");
document.getElementById("consent-json").textContent = JSON.stringify(
Fides.consent,
null,
2,
);
});

window.addEventListener("FidesUIShown", () => {
// Log event timing
Expand Down

0 comments on commit 88a32f0

Please sign in to comment.