VEuPathDB / EbrcWebsiteCommon

Apache License 2.0
3 stars 3 forks source link

Fix race condition DataRestrictionDaemon #59

Closed jtlong3rd closed 3 years ago

jtlong3rd commented 3 years ago

This PR:

  1. Fixes a race condition which was causing the DataRestrictionModal to be wrongly cleared. (Also requires the companion PR for ClinEpiWebsite to be merged.)
  2. Updates Showcase so that the StudyCard's permissions can be passed through the containing Showcase, as opposed to wrapping StudyCard via withPermissions. (Motivation: wrapping the StudyCard via withPermissions causes the former to render slowly, because withPermissions defers rendering the StudyCard until the permissions have been fetched.)
  3. Eliminates some related (and unnecessary) /permissions service calls on page load.

Some more details about the race condition

The “race” is between the DataRestrictionDaemon, which dispatches a redux action to clear the modal every time the route’s pathname changes, and various attemptActions which are executed when certain “pages” are loaded (and which, on action denial, dispatch a redux action to show the modal).

Under normal circumstances, the former will always happen before the latter, but in web-eda local dev, it's possible to make the latter happen before the former. (For example, hit “reload” when on a ResrictedPage for which you don’t have access. The page contents will [correctly] be blurred, but the modal will not appear.)

The culprit is that the DataRestrictionDaemon is wrapped in withPermissions, which defers rendering the wrapped component until the permissions are fetched.

This PR and the companion PR for ClinEpiWebsite resolve this issue by “asynchronously” retrieving the permissions for DataRestrictionDaemon using a hook within the daemon, instead of “synchronously” deferring the daemon’s rendering until the permissions are fetched. Doing so will cause the modal-clearing-action to be dispatched immediately.