Skip to content
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

Merged
merged 4 commits into from
Feb 6, 2023

Conversation

fallaciousreasoning
Copy link
Contributor

@fallaciousreasoning fallaciousreasoning commented Jan 23, 2023

Resolves brave/brave-browser#27914

Note: I also removed a bunch of unused code I encountered.

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run lint, npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

See issue

@github-actions github-actions bot added the CI/storybook-url Deploy storybook and provide a unique URL for each build label Jan 23, 2023
@@ -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)
Copy link
Contributor Author

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
}
{
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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 😄

Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor

@sangwoo108 sangwoo108 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Member

@simonhong simonhong left a comment

Choose a reason for hiding this comment

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

++ 👍🏼

@fallaciousreasoning fallaciousreasoning force-pushed the bn-crash branch 3 times, most recently from 48a9918 to 18d2c5a Compare February 1, 2023 00:27
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@fallaciousreasoning fallaciousreasoning enabled auto-merge (squash) February 5, 2023 21:41
@fallaciousreasoning fallaciousreasoning merged commit 29335e0 into master Feb 6, 2023
@fallaciousreasoning fallaciousreasoning deleted the bn-crash branch February 6, 2023 21:02
@github-actions github-actions bot added this to the 1.50.x - Nightly milestone Feb 6, 2023
fallaciousreasoning added a commit that referenced this pull request Feb 19, 2023
…16788)

* Use hook instead of pass through

* Remove unused properties

* Ensure publishers are pushed when opting in

* Fix Storybook
kjozwiak pushed a commit that referenced this pull request Feb 23, 2023
…earn More content in its tab (#17287)

Fix Brave News crash on opt-in after navigating & cleanup settings (#16788)

* Use hook instead of pass through

* Remove unused properties

* Ensure publishers are pushed when opting in

* Fix Storybook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Brave News Customize window is blank after loading Learn More content in its tab
4 participants