Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
Bug 1520888 - Ensure spocs don't load over a rec. (#4701)
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottDowne committed Jan 23, 2019
1 parent 1f109ab commit 148eae0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions common/Reducers.jsm
Expand Up @@ -60,6 +60,7 @@ const INITIAL_STATE = {
spocs_endpoint: "",
lastUpdated: null,
data: {}, // {spocs: []}
loaded: false,
},
},
Search: {
Expand Down Expand Up @@ -478,6 +479,7 @@ function DiscoveryStream(prevState = INITIAL_STATE.DiscoveryStream, action) {
...prevState.spocs,
lastUpdated: action.data.lastUpdated,
data: action.data.spocs,
loaded: true,
},
};
}
Expand Down
Expand Up @@ -115,6 +115,14 @@ export class _DiscoveryStreamBase extends React.PureComponent {

renderComponent(component) {
let rows;
const {spocs} = this.props.DiscoveryStream;

// TODO: Can we make this a bit better visually while it loads?
// If this component expects spocs,
// wait until spocs are loaded before attempting to use it.
if (component.spocs && !spocs.loaded) {
return null;
}

switch (component.type) {
case "TopSites":
Expand Down
2 changes: 2 additions & 0 deletions lib/DiscoveryStreamFeed.jsm
Expand Up @@ -168,6 +168,8 @@ this.DiscoveryStreamFeed = class DiscoveryStreamFeed {
await this.cache.set("spocs", spocs);
} else {
Cu.reportError("No response for spocs_endpoint prop");
// Use old data if we have it, otherwise nothing.
spocs = spocs || {};
}
}

Expand Down
1 change: 1 addition & 0 deletions test/unit/common/Reducers.test.js
Expand Up @@ -682,6 +682,7 @@ describe("Reducers", () => {
spocs_endpoint: "",
data: [1, 2, 3],
lastUpdated: 123,
loaded: true,
});
});
it("should handle no data from DISCOVERY_STREAM_SPOCS_UPDATE", () => {
Expand Down

0 comments on commit 148eae0

Please sign in to comment.