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

Bug/DES-2671: Fix a race condition caused by async template loading #1160

Merged
merged 2 commits into from
Jan 24, 2024

Conversation

jarosenb
Copy link
Member

Overview:

It's possible for angularJS to force a page refresh under certain conditions. It seems to trigger if the route changes while a controller is fetching data. This was causing weird interactions with react-router, with (to my best guess) this sequence of events occurring:

  1. The page loads and angular/react components begin rendering
  2. The notification bell element begins fetching its template from {% static 'scripts/notifications/html/badge.html' %}
  3. WHILE this fetch is occurring, react-router finishes initializing and triggers a redirect. This can happen if the user visits a deprecated page and we need to point them to the correct URL.
  4. angular detects the change to the browser location and triggers a page reload using this logic:
if (!startsWith(newUrl, appBaseNoFile)) {
  // If we are navigating outside of the app then force a reload
  $window.location.href = newUrl;
  return;
}

This is a race condition, since angular only subscribes to URL change detection while the template is being fetched. The solution is to refactor the notification bell as a component and include it in the bundle, so that the async data fetching behavior never runs.

PR Status:

  • Ready.
  • Work in Progress.
  • Hold.

Related Jira tickets:

Summary of Changes:

Use an angularJS component for the notification bell instead of loading the template asynchronously.

Testing Steps:

  1. Visit the dev site and confirm that the notification bell renders as expected.

UI Photos:

Notes:

@jarosenb jarosenb merged commit 58b6070 into main Jan 24, 2024
3 checks passed
@jarosenb jarosenb deleted the bug/DES-2671--notification-badge-race-condition branch January 24, 2024 19:59
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.

1 participant