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

Speed up FidesJS initialization #4896

Merged
merged 18 commits into from
May 21, 2024
Merged

Conversation

gilluminate
Copy link
Contributor

@gilluminate gilluminate commented May 17, 2024

Closes PROD-2082

Description Of Changes

FidesJS' initialization was depending on the DOM to complete loading. Here we change that initialization to fire off when the document is loaded and the DOM is in interactive state instead, ensuring that FidesJS is available much faster. However, in turn this creates a race condition for dynamic pages and slow loading pages between FidesJS initialization and having the page render the appropriate containers and links. That issue is addressed here as well.

Code Changes

  • render fidesJS sooner by waiting for readyState to be interactive instead of complete (this is the soonest we can safely proceed with the script).
  • If the modal link isn't available, set up polling to check if it gets added to the page later.
  • If the embed container isn't available but fides_embed is set to true, set up polling to check if it gets added to the page later.
  • Configure demo pages to be able to pass a delay to the link and container to more easily test the polling.
  • Include a check for modalLinkId to see if it's an empty string rather than a real value or null. If it has and empty string, we don't look for the modal link at all. This effectively provides an "opt out" for developers who are rolling their own link using Fides.showModal();

Steps to Confirm

verify FidesJS is initializing faster

  1. Update the fides-js-demo.html page in Privacy Center and uncomment these lines of code:
<!-- <h2>Huge Image</h2>
<img...
...
/> -->
  1. build and start the privacy center and visit http://localhost:3000/fides-js-demo.html?geolocation=eea
  2. The browser tab will keep spinning while the image loads very slowly because it's so big. This indicates that the DOM is still in an interactive state, and not complete. Previously this could have caused the overlay banner to appear after the image had fully loaded. Now the banner will appear immediately despite the slow image. Verify that this is the case.
  3. revert changes to fides-js-demo.html

verify the DOM checker polling is working

  1. Update the top script code in fides-js-demo.html:
  • set window.render_delay = 5000; to cause the page to update with embed container and modal link after 5 seconds
  • uncomment this code:
// window.fides_overrides = {
//   fides_embed: true,
// };
  1. build and start the privacy center and visit http://localhost:3000/fides-js-demo.html?geolocation=us-ca
  2. watch the console logs to see messages about not finding the embed ID or the modal link
  3. After 5 seconds the embed and link should load, update the console that they were found, and get bound (the link is clickable to open the overlay)
  4. revert changes to fides-js-demo.html

Pre-Merge Checklist

  • All CI Pipelines Succeeded
  • Issue Requirements are Met
  • Update CHANGELOG.md

Copy link

vercel bot commented May 17, 2024

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

Name Status Preview Comments Updated (UTC)
fides-plus-nightly ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2024 8:09pm

@gilluminate gilluminate force-pushed the PROD-2082-fides-js-initialization-is branch from 04954b4 to d285545 Compare May 17, 2024 16:46
Copy link

cypress bot commented May 17, 2024

Passing run #7835 ↗︎

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 fc537dd into 5f2d512...
Project: fides Commit: 474fe005ad ℹ️
Status: Passed Duration: 00:34 💡
Started: May 21, 2024 8:17 PM Ended: May 21, 2024 8:18 PM

Review all test suite changes for PR #4896 ↗︎

@gilluminate gilluminate force-pushed the PROD-2082-fides-js-initialization-is branch from 92f4d68 to f4a8e46 Compare May 17, 2024 17:59
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.

This approach looks pretty good. Couple bugs and comments in here

clients/fides-js/src/docs/fides.ts Outdated Show resolved Hide resolved
clients/fides-js/src/lib/initOverlay.ts Show resolved Hide resolved
clients/fides-js/src/lib/initOverlay.ts Outdated Show resolved Hide resolved
clients/fides-js/src/lib/initOverlay.ts Show resolved Hide resolved
clients/fides-js/src/lib/initOverlay.ts Outdated Show resolved Hide resolved
clients/fides-js/src/lib/initOverlay.ts Outdated Show resolved Hide resolved
@gilluminate gilluminate force-pushed the PROD-2082-fides-js-initialization-is branch from eec5b73 to abef798 Compare May 17, 2024 21:29
@gilluminate gilluminate requested a review from NevilleS May 17, 2024 23:51
@gilluminate gilluminate marked this pull request as ready for review May 17, 2024 23:51
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.

Final hesitation...

clients/fides-js/src/components/Overlay.tsx Outdated Show resolved Hide resolved
@gilluminate gilluminate marked this pull request as draft May 21, 2024 15:34
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.

Thanks 👍. This feels pretty good now

@gilluminate gilluminate merged commit 587eda6 into main May 21, 2024
13 checks passed
@gilluminate gilluminate deleted the PROD-2082-fides-js-initialization-is branch May 21, 2024 20:43
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