-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[🐞] Error: Actions can not be invoked within the server during SSR. #5874
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
Comments
Hmm, so the QwikCityMockProvider should somehow make it so that actions run locally? Or should they be mocked entirely? Sounds feasible but needs a good think about the API. PRs very welcome. |
That's correct, in this context I'd want to mock the fetch calls for testing, however that doesn't mean there isn't a scenario in which one would want the action to run as normal as well. |
@wmertens Help me understand the QwikCityMockProvider. If I look at https://github.com/QwikDev/qwik/blob/main/packages/qwik-city/runtime/src/qwik-city-component.tsx#L130 and https://github.com/QwikDev/qwik/blob/main/packages/qwik-city/runtime/src/qwik-city-component.tsx#L578 the Can you provide more thoughts on how this would be implemented? I'm happy to do some work here but I need to understand what exactly is missing and what needs to be either mocked out or filled it, in isn't exactly clear. The huge windfall here would be the ability to rapidly test one's app with mocked data. The speed we could test if this was in place would be an order of magnitude faster vs cypress or playwright or any of the e2e testing libraries. |
Previously the SSR‐guard in `server-functions.ts` unconditionally threw whenever `isServer` was true, which blocked invocation of `routeAction$` under Vitest+JSDOM (and the QwikCityMockProvider) in user tests. Now we narrow the guard to: if (isServer && typeof window === 'undefined') { throw …; } After this fix: - True SSR(no 'window') still throws an error as beforev - JSDOM/Vitest tests(and browsers) have a global 'window', do not throw the error, and returns a promise This will unblock testing of actions in JSDOM environments without impacting real SSR safety Closes QwikDev#5874
Which component is affected?
Qwik Runtime
Describe the bug
When attempting to vitest a component that invokes a
routeAction$
I'm getting the error:I thought that vitest would render using the node environment and thus SSR and I could mock out the HTTP API call that my action is ultimately making. This is not the case though and I can't find any good documentation on how to do this.
Where within the RemoveUsers component it calls
action.submit(data as unknown as FormData)
which ultimately makes an HTTP POST call.Reproduction
http://no.repro.url
Steps to reproduce
No response
System Info
Additional Information
No response
The text was updated successfully, but these errors were encountered: