fix(carousel): improve carousel context handling with async context#2033
Open
IMinchev64 wants to merge 11 commits intomasterfrom
Open
fix(carousel): improve carousel context handling with async context#2033IMinchev64 wants to merge 11 commits intomasterfrom
IMinchev64 wants to merge 11 commits intomasterfrom
Conversation
Contributor
There was a problem hiding this comment.
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
firstUpdatedlifecycle hook - Replaced all direct
_carouselreferences with_carouselInstancegetter 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 |
rkaraivanov
reviewed
Dec 11, 2025
rkaraivanov
approved these changes
Dec 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes this Bug
Current carousel context wiring:
ContextProvider(carouselContext) when it constructs. Slides use@consume({ context: carouselContext, subscribe: true })to grab a_carouselref._carouselstays undefined.Why this causes issues (Blazor timing):
_carouselblows up.Why refactor following tile manager:
updateComplete, and the provider re-sets its value once ready. This avoids the race.