-
Notifications
You must be signed in to change notification settings - Fork 893
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
Fix Brave News crash on opt-in after navigating & cleanup settings #16788
Conversation
@@ -69,8 +69,8 @@ export default function FeedCard (props: { | |||
const publisher = usePublisher(props.publisherId) | |||
const { followed, setFollowed } = usePublisherFollowed(props.publisherId) | |||
|
|||
const backgroundColor = publisher.backgroundColor || getCardColor(publisher.feedSource?.url || publisher.publisherId) | |||
const { url: coverUrl, setElementRef } = useLazyUnpaddedImageUrl(publisher.coverUrl?.url, { | |||
const backgroundColor = publisher?.backgroundColor || getCardColor(publisher?.feedSource?.url || publisher?.publisherId) |
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.
Note: The fix doesn't actually need this but its should prevent future crashes in the same vein
@@ -362,19 +359,6 @@ export default class Settings extends React.PureComponent<Props, State> { | |||
/> | |||
) : null | |||
} | |||
{ |
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.
This is no longer used, now we've switched completely to Brave News V2
@@ -630,6 +630,14 @@ void BraveNewsController::ConditionallyStartOrStopTimer() { | |||
timer_prefetch_.Start(FROM_HERE, base::Minutes(1), this, | |||
&BraveNewsController::Prefetch); | |||
} | |||
|
|||
GetPublishers(base::BindOnce([](BraveNewsController* controller, Publishers publishers) { |
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.
This is the actual fix: Push publishers to all listeners on opt-in
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.
I'm curious what would happen if there's no in-memory publisher data and it takes too long for the api request helper in publisher controller to get the publisher data. Shortly, would the NTP crash if the callback here is invoked later than the page loading?
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.
So the actual crash was being caused because the page was asking for some suggestions, and getting them back. However, we hadn't pushed the publishers to the front end at that point, so we had an empty list of publishers, but a bunch of suggestedPublisherIds.
GetSuggestedPublisherIds
depends on GetPublishers
, so if we get suggestions then the api request for publishers must have completed.
So to answer your question, no 😄
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.
Thanks @fallaciousreasoning ! It can't happen logically.
@@ -630,6 +630,14 @@ void BraveNewsController::ConditionallyStartOrStopTimer() { | |||
timer_prefetch_.Start(FROM_HERE, base::Minutes(1), this, | |||
&BraveNewsController::Prefetch); | |||
} | |||
|
|||
GetPublishers(base::BindOnce([](BraveNewsController* controller, Publishers publishers) { |
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.
I'm curious what would happen if there's no in-memory publisher data and it takes too long for the api request helper in publisher controller to get the publisher data. Shortly, would the NTP crash if the callback here is invoked later than the page loading?
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.
LGTM 👍
2d75dc0
to
c109c7c
Compare
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.
++ 👍🏼
48a9918
to
18d2c5a
Compare
18d2c5a
to
e490a50
Compare
A Storybook has been deployed to preview UI for the latest push |
…16788) * Use hook instead of pass through * Remove unused properties * Ensure publishers are pushed when opting in * Fix Storybook
Resolves brave/brave-browser#27914
Note: I also removed a bunch of unused code I encountered.
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
wikinpm run lint
,npm run presubmit
wiki,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan:
See issue