-
-
Notifications
You must be signed in to change notification settings - Fork 42
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Are you using the latest version of this library?
- I verified that the issue exists in the latest next-safe-action release
Is there an existing issue for this?
- I have searched the existing issues and found nothing that matches
Describe the bug
Importing anything from next-safe-action/hooks
causes Vitest tests to crash due to how React is being imported in that file.
I don't fully understand how the module resolution works here so I cannot tell you exactly why this happens, but I do know that making the following change in the hooks.mjs
file fixes the problem 👇
diff --git a/dist/hooks.mjs b/dist/hooks.mjs
index 636b65d50449fa41e913bb5bb632370f8f4f9df9..7f48d3c48278d76c36a73ae6bf99bed51ba5679b 100644
--- a/dist/hooks.mjs
+++ b/dist/hooks.mjs
@@ -3,7 +3,8 @@
// src/hooks.ts
import { isNotFoundError } from "next/dist/client/components/not-found.js";
import { isRedirectError } from "next/dist/client/components/redirect.js";
-import { useCallback, useEffect, useOptimistic, useRef, useState, useTransition } from "react";
+import pkg from 'react';
+const { useCallback, useEffect, useOptimistic, useRef, useState, useTransition } = pkg;
That's a patch I've applied temporarily to fix the issue in my project.
Reproduction steps
- Open https://stackblitz.com/edit/vitest-dev-vitest-6lgc1a?file=test%2Fbasic.test.tsx
- See test fail
- Comment out the 'next-safe-action/hooks' import and the useAction invocation further down
- See test pass
Expected behavior
The test should pass without failing due to how React is being imported.
Reproduction example
https://stackblitz.com/edit/vitest-dev-vitest-6lgc1a?file=test%2Fbasic.test.tsx
Operating System
macOS
Library version
6.0.1
Additional context
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working