Skip to content

Profile interface and web components lifecycle improvements#427

Merged
cubap merged 3 commits intomainfrom
418-profile-flashes
Feb 4, 2026
Merged

Profile interface and web components lifecycle improvements#427
cubap merged 3 commits intomainfrom
418-profile-flashes

Conversation

@thehabes
Copy link
Copy Markdown
Member

@thehabes thehabes commented Feb 3, 2026

Summary

Fixes #418 - Eliminates the "flash" UI behavior on the /profile page caused by multiple redundant API calls and render cycles.

Problem

The profile page had a cascade effect where:

  • 5 components called TPEN.attachAuthentication(this) which sets the tpen-user-id attribute
  • 4 profile components observed this attribute and each triggered User.getProfile()
  • Each getProfile() dispatched tpen-user-loaded event
  • All 4 components listened for this event and re-rendered

Result: Up to 16 render cycles (4 events × 4 listeners) plus 3 redundant getUserProjects() API calls.

Solution

Created two new utilities following the existing onProjectReady pattern:

  • utilities/userReady.js - Handles user data readiness with caching and single-fetch guarantee
  • utilities/userProjectsReady.js - Handles user projects with caching and single-fetch guarantee

Refactored 4 profile components to use these utilities instead of attribute observation:

  • components/user-profile/index.js
  • components/user-profile/userStats.js
  • components/user-profile/report.js
  • components/user-profile/contributionActivity.js

Key Changes

  • Module-level singleton flags prevent concurrent API fetches
  • _isRendering guards prevent double renders when callbacks fire quickly
  • Proper cleanup via unsubscribe functions in disconnectedCallback
  • Removed observedAttributes and attributeChangedCallback (internal implementation detail, not a breaking change)

Expected Results

Metric Before After
tpen-user-loaded events 4 1
getUserProjects() calls 3 1
Render cycles Up to 16 4 (one per component)
Visual flashing Yes No

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 3, 2026

@thehabes thehabes changed the title Profile interface and web component lifecycle improvements Profile interface and web components lifecycle improvements Feb 3, 2026
@thehabes thehabes self-assigned this Feb 3, 2026

This comment was marked as resolved.

@thehabes thehabes marked this pull request as ready for review February 3, 2026 20:59
@thehabes thehabes requested a review from cubap February 3, 2026 21:00
@cubap cubap merged commit e8b6760 into main Feb 4, 2026
2 checks passed
@cubap cubap deleted the 418-profile-flashes branch February 4, 2026 17:51
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.

Profile page flashes and loads data multiple times on initial load

3 participants