-
Notifications
You must be signed in to change notification settings - Fork 37
Description
Describe the bug
When using create resource like const [data] = createResource(asyncFetcher, options), there is a lint error: "This tracked scope should not be async."
To Reproduce
Add code similar to the description, and note the lint error:
const [intializedResource] = createResource(async () => [], {
initialValue: [],
});See https://playground.solidjs.com/anonymous/b67979b9-c72b-4b52-91e1-dcec2b445ade for a more extensive example.
Expected behavior
When the fetcher function does not contain reactive values, there should be no lint error. createResource(nonReactiveFetcher, options) is a legit use of createResource.
Environment (please complete the following information):
- OS: [Windows 11, Ubuntu 24.04]
- Node version (
node --version): v22 eslint-plugin-solidversion (npm list eslint-plugin-solid/yarn why eslint-plugin-solid): 0.14.5 and whatever is in solid playgroundeslintversion (npm list eslint/yarn why eslint): 9.20.1 and whatever is in solid playground
Additional context
I believe I can see the source of the issue. L970 of rules/reactivity.ts has this in the conditional:
(matchImport("createResource", callee.name) && node.arguments.length >= 2)Since the arguments.length of createResource(fetcher, opts) is 2, this state is incorrectly pushed into the tracked scopes.
I believe the solution will require a check similar to Solid's implementation of createResource:
if (typeof node.arguments[1] === "function") { /* There is a source */ }
So the solution may be as simple as
(matchImport("createResource", callee.name) && typeof node.arguments[1] === "function")- I would be willing to contribute a PR to fix this issue