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

feat(docs): add prefetching example from tanstack-query examples #40

Merged
merged 7 commits into from
Oct 25, 2022

Conversation

michaelxvoelker
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #34

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@stackblitz
Copy link

stackblitz bot commented Oct 23, 2022

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@michaelxvoelker
Copy link
Contributor Author

Looks like the default query function have some side effects. 🤔 The example implemented in this PR is only working properly, when I remove the QUERY_CLIENT_CONFIG provider from the providers array in main.ts. Currently, every click on the character name in the list will run another network request.

@NetanelBasal
Copy link
Member

@michaelxvoelker sounds weird 🤔. Can you please add a debugger inside the default query function and see if it's stopped there?

@michaelxvoelker
Copy link
Contributor Author

michaelxvoelker commented Oct 24, 2022

I found the culprit. The provided QUERY_CLIENT_CONFIG

return <QueryClientConfig>{
          defaultOptions: {
            queries: {
              queryFn,
            },
          },
        };

will overwrite the default configuration of staleTime: Infinity in QueryClient:

export const QueryClient = new InjectionToken<QueryCore>('QueryClient', {
  providedIn: 'root',
  factory() {
    const options = inject(QUERY_CLIENT_OPTIONS);

    return new QueryCore({
      defaultOptions: {
        queries: {
          staleTime: Infinity,
          ...options?.defaultOptions?.queries,
        },
      },
      ...options,
    });
  },
});

Is this intentional? 🤔

Looks like ...options?.defaultOptions?.queries, is unnecessary. If options?.defaultOptions exists, ...options, will overwrite it anyways and ultimately the staleTime: Infinity.

@NetanelBasal
Copy link
Member

Yes, it's a bug.

@michaelxvoelker
Copy link
Contributor Author

I can provide a fix within this PR.

@NetanelBasal
Copy link
Member

Go ahead

@michaelxvoelker michaelxvoelker changed the title feat: add prefetching example from tanstack-query examples feat(docs): add prefetching example from tanstack-query examples Oct 25, 2022
@NetanelBasal NetanelBasal merged commit 7f3aa91 into ngneat:main Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants