Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Hotfix refetch loading state #67

Merged
merged 2 commits into from
Jun 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Expect active development and potentially significant breaking changes in the `0.x` track. We'll try to be diligent about releasing a `1.0` version in a timely fashion (ideally within 1 or 2 months), so that we can take advantage of SemVer to signify breaking changes from that point on.

### v.0.3.7

Bug: Reset loading state when a refetched query has returned

### v0.3.6

Bug: Loading state is no longer true on uncalled mutations.
Expand Down
2 changes: 1 addition & 1 deletion src/connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export default function connect(opts?: ConnectOptions) {

// only rerender child component if data has changed
// XXX should we rerender while errors are present?
if (!isEqual(oldData, data) || errors) {
if (!isEqual(oldData, data) || errors || this.data[key].loading) {
this.hasQueryDataChanged = true;
}

Expand Down
88 changes: 88 additions & 0 deletions test/connect/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,94 @@ describe('queries', () => {
);
});

it('resets the loading state after a refetched query even if the data doesn\'t change', (done) => {

const query = gql`
query people {
allPeople(first: 1) {
people {
name
}
}
}
`;

const data1 = {
allPeople: {
people: [
{
name: 'Luke Skywalker',
},
],
},
};

const networkInterface = mockNetworkInterface(
{
request: { query: query },
result: { data: data1 },
},
{
request: { query: query },
result: { data: data1 },
}
);

const client = new ApolloClient({
networkInterface,
});

function mapQueriesToProps() {
return {
people: { query },
};
};

let hasRefetched = false;
let hasRefetchedAndReturned = false;
@connect({ mapQueriesToProps })
class Container extends React.Component<any, any> {
componentWillReceiveProps(nextProps) {

if (hasRefetchedAndReturned) {
expect(nextProps.people.loading).to.be.false;
done();
return;
}

if (hasRefetched) {
expect(nextProps.people.loading).to.be.true;
hasRefetchedAndReturned = true;
return;
}
}

componentDidUpdate(prevProps) {

if (prevProps.people.loading && !this.props.people.loading) {

if (hasRefetched) {
return;
}

hasRefetched = true;
this.props.people.refetch()
return;
}

}
render() {
return <Passthrough {...this.props} />;
}
};

mount(
<ProviderMock client={client}>
<Container />
</ProviderMock>
);
});

it('resets the loading state when refetching', (done) => {
const store = createStore(() => ({
foo: 'bar',
Expand Down