Skip to content

Commit fdaab91

Browse files
committed
fix(feed): inject initial preferences into HeadlinesFeedBloc
Updates the router to provide the `HeadlinesFeedBloc` with the initial `UserContentPreferences` from the `AppBloc` state upon creation. This resolves a race condition where the feed UI could be built before the `HeadlinesFeedBloc` received the user's saved filters from the `AppBloc` stream. By injecting the initial state via the constructor, the `SavedFiltersBar` is now guaranteed to display the correct filters immediately for all users.
1 parent dd5c8b9 commit fdaab91

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/router/router.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,21 @@ GoRouter createRouter({
346346
providers: [
347347
BlocProvider(
348348
create: (context) {
349+
// Read the AppBloc once to get the initial state.
350+
final appBloc = context.read<AppBloc>();
351+
349352
return HeadlinesFeedBloc(
350353
headlinesRepository: context
351354
.read<DataRepository<Headline>>(),
352355
feedDecoratorService: feedDecoratorService,
353-
appBloc: context.read<AppBloc>(),
356+
appBloc: appBloc,
354357
inlineAdCacheService: inlineAdCacheService,
358+
// Prime the HeadlinesFeedBloc with the initial user
359+
// preferences. This prevents a race condition where the
360+
// feed is displayed before the bloc receives the saved
361+
// filters from the AppBloc stream.
362+
initialUserContentPreferences:
363+
appBloc.state.userContentPreferences,
355364
);
356365
},
357366
),

0 commit comments

Comments
 (0)