-
Notifications
You must be signed in to change notification settings - Fork 9
fix(carousel): improve carousel context handling with async context #2033
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
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 |
There was a problem hiding this 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.
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.