Skip to content

Conversation

@IMinchev64
Copy link

Closes this Bug

Current carousel context wiring:

  • The carousel sets up a Lit ContextProvider (carouselContext) when it constructs. Slides use @consume({ context: carouselContext, subscribe: true }) to grab a _carousel ref.
  • The consumer request fires once when the slide connects. If the carousel isn't upgraded/publishing yet (common if Blazor renders wrappers and upgrades happen later), that request is missed and _carousel stays undefined.

Why this causes issues (Blazor timing):

  • If I understand correctly, Blazor renders web components, then the custom elements upgrade. Slides can connect before the carousel has attached its provider. Because the consume decorator issues a one-time request, there's no retry, so the ref never gets set. Downstream slide logic that expects _carousel blows up.

Why refactor following tile manager:

  • Tile manager uses an async context consumer created after updateComplete, and the provider re-sets its value once ready. This avoids the race.
  • Copying that pattern (or otherwise deferring/retrying the context request) ensures slides always get a valid carousel ref, eliminating the timing gap seen in Blazor.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a race condition in carousel context initialization that occurs when slides connect before the carousel component has fully upgraded, particularly in Blazor scenarios. The fix replaces the synchronous @consume decorator with an async context consumer pattern (borrowed from tile-manager), ensuring slides reliably obtain their carousel reference regardless of initialization timing.

Key changes:

  • Introduced async context consumer in carousel slides to handle delayed context availability
  • Added explicit context setting in carousel's firstUpdated lifecycle hook
  • Replaced all direct _carousel references with _carouselInstance getter for fallback logic

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/components/carousel/carousel.ts Extracts context setting into _setCarouselContext() method and calls it in firstUpdated() to ensure context is available after component upgrade
src/components/carousel/carousel-slide.ts Replaces @consume decorator with async context consumer and adds _carouselInstance getter to provide fallback access pattern

@IMinchev64 IMinchev64 requested a review from Copilot December 11, 2025 13:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants