-
Notifications
You must be signed in to change notification settings - Fork 72
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
Fix cached translation issues with Minimal TCF experience #5306
Conversation
user's locale includes configured as override anyway
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
7ea867f
to
a525282
Compare
useEffect(() => { | ||
if (!currentLocale && i18n.locale) { | ||
setCurrentLocale(i18n.locale); | ||
} | ||
}, [currentLocale, i18n.locale, setCurrentLocale]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i18n-context was updated which made this unnecessary
useEffect(() => { | ||
if (!currentLocale) { | ||
// initialize the i18n locale using the minimal experience | ||
setCurrentLocale(minExperienceLocale); | ||
} | ||
}, [currentLocale, minExperienceLocale, setCurrentLocale]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i18n-context was updated which made this unnecessary
// We need to track if the experience and GVL translations are loading separately | ||
// because they are loaded asynchronously and we need to know when both are done | ||
// in order to set the i18n loading state. | ||
let isExperienceLoading = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was causing the globe to spin unnecessarily while GVL translations loaded in the background. GVL is only needed for Modal, so this is overkill on the banner.
fides Run #10023
Run Properties:
|
Project |
fides
|
Branch Review |
refs/pull/5306/merge
|
Run status |
Passed #10023
|
Run duration | 00m 37s |
Commit |
84353fdef6 ℹ️: Merge 78060f3695458b6392e39b2ed05225c393baa1eb into ec2d33b9d50c3008e67b54f007e3...
|
Committer | Jason Gill |
View all properties for this run ↗︎ |
Test results | |
---|---|
Failures |
0
|
Flaky |
0
|
Pending |
0
|
Skipped |
0
|
Passing |
4
|
Upgrade your plan to view test results. | |
View all changes introduced in this branch ↗︎ |
const onSetCurrentLocale = useCallback( | ||
(locale: string) => { | ||
i18nInstance.activate(locale); | ||
setCurrentLocale(locale); | ||
}, | ||
[i18nInstance, setCurrentLocale], | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was all overkill and was causing some problems. Just use the ol' i18n.locale
and i18n.activate
as intended
15de4d5
to
78060f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work! The vary header is present and working in Firefox, apparently chrome doesn't respect it :(, but even if the response is cached initially your 2nd fix handles it nicely so the users get the correct language. Approved!
fides Run #10032
Run Properties:
|
Project |
fides
|
Branch Review |
main
|
Run status |
Passed #10032
|
Run duration | 00m 37s |
Commit |
1b1ab1fb62: Fix cached translation issues with Minimal TCF experience (#5306)
|
Committer | Jason Gill |
View all properties for this run ↗︎ |
Test results | |
---|---|
Failures |
0
|
Flaky |
0
|
Pending |
0
|
Skipped |
0
|
Passing |
4
|
Upgrade your plan to view test results. | |
View all changes introduced in this branch ↗︎ |
Closes PROD-2764
Description Of Changes
When the fides.js script gets cached, but a user changes their browser's language, we get into a weird state with multiple languages (especially after the GVL languages load correctly).
Code Changes
Accept_Language
in theVary
to instruct caches to reset when language changeswindow.fides_overrides.fides_locale
) and load the available translation until full TCF Experience is ready with the correct language.Steps to Confirm
fides-js-demo.html
:Replace:
With:
window
setting, it will first load the English banner and the language picker's globe icon should immediately start spinning to indicate a language is loading. Once the full experience loads, it should replace English with the configured language of French. This is just an edge case we need to handle gracefully.Pre-Merge Checklist
CHANGELOG.md