[angular-query] Accessing `.data` kicks off the `CreateQueryOptions` function
@arnoud-dv arbeitet bereits daran.
Seit 30.5.2024.
Bewertung
Dieses Issue wurde noch nicht bewertet.
Beschreibung
Describe the bug
I have a very simple use case when I do not have an error handler or loading indicator, so I am trying to create a query and save a reference to only the .data signal. I am not invoking the signal immediately, but saving a reference to only the signal.
ie: something = injectQuery(() => { ... }).data;
I am using a signal input as a part of my query key.
I wanted to make that signal input required, but in doing so, Angular started throwing a runtime error saying that the required input had no value. From the outside, I was always passing a value in for the input.
After I reverted the input back to not required, I noticed that the CreateQueryOptions function I was using for the signal was actually being invoked immdeiately upon construction of the component as well as after the input value was set.
I was able to narrow it down and realize that this only happens when I have .data on the end in order to store off the signal. I was only doing this for the sake of simplicity. Nothing else in my code needs a reference to the query itself. They only need access to the data signal, so that's what I stored off. I was not expecting that to immediately invoke the options, and thus access the signal input before it is initialized.
I can confirm that if I store the reference to the entire query (ie: without .data), then it works correctly (and I can add .required if I want to). It confuses me because either way, my template will access the signal "immediately" via either query.data() or data(). But I suppose that is actually when rendering, vs at construct time when I store off .data.
Is this just bad practice the way I am trying to do it, or would this actually be considered a bug?
Your minimal, reproducible example
Steps to reproduce
- Open the repro
- Look in the TanStack devtools and see that the "broken" example query ran twice. Once with
null, and once the correct result:
- Now, change
someInputto berequired(see commented out line where the input is defined) - You will get a runtime error in the console like so:
Expected behavior
I would expect that I can store off a reference to the .data signal whenever I want without it accessing signal inputs too soon.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: MacOS 14.5
- Browser: Edge
- Version: 125.0.2535.67
Tanstack Query adapter
angular-query
TanStack Query version
5.40.0
TypeScript version
5.3.3
Additional context
No response
- Vorherrschende Sprache
- TypeScript
- Sterne
- 50.3k
- Forks
- 4.2k
- Ø Merge
- 22 Std. 33 Min.
- Gemergte PRs (30 T.)
- 214
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus TanStack/query
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 40/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
bcgov/bc-wallet-mobile#4761 · 1 Kommentar ·
-
external-issue to-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
-
area-deployment area-integrations triage:bot-seen
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 86/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
refactor
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100