lucaong / react-minisearch

React integration for the MiniSearch client side full-text search library
MIT License
49 stars 8 forks source link

Current master is not working [a23e198] #12

Closed Kjaer closed 3 years ago

Kjaer commented 3 years ago

Hello there @lucaong,

I was recently used the minisearch hook you did here and preparing for a PR for improvement. But I stuck on failing master. Here is what I did:

Here is the full output of my browser's dev tools console

Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
    at resolveDispatcher (webpack-internal:///./node_modules/react-minisearch/node_modules/react/cjs/react.development.js:1465)
    at Object.useState (webpack-internal:///./node_modules/react-minisearch/node_modules/react/cjs/react.development.js:1496)
    at useMiniSearch (webpack-internal:///./node_modules/react-minisearch/dist/react-minisearch.js:38)
    at App (webpack-internal:///./src/app.jsx:46)
    at renderWithHooks (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:14803)
    at mountIndeterminateComponent (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:17482)
    at beginWork (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:18596)
    at HTMLUnknownElement.callCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:188)
    at Object.invokeGuardedCallbackDev (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:237)
    at invokeGuardedCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:292)
webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:19527 The above error occurred in the <App> component:
    in App (created by WithDocuments)
    in WithDocuments

Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://fb.me/react-error-boundaries to learn more about error boundaries.
logCapturedError @ webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:19527
webpack-internal:///./node_modules/react-minisearch/node_modules/react/cjs/react.development.js:1465 Uncaught (in promise) Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
    at resolveDispatcher (webpack-internal:///./node_modules/react-minisearch/node_modules/react/cjs/react.development.js:1465)
    at Object.useState (webpack-internal:///./node_modules/react-minisearch/node_modules/react/cjs/react.development.js:1496)
    at useMiniSearch (webpack-internal:///./node_modules/react-minisearch/dist/react-minisearch.js:38)
    at App (webpack-internal:///./src/app.jsx:46)
    at renderWithHooks (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:14803)
    at mountIndeterminateComponent (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:17482)
    at beginWork (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:18596)
    at HTMLUnknownElement.callCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:188)
    at Object.invokeGuardedCallbackDev (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:237)
    at invokeGuardedCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:292)

I still wish to make my improvement PR once fixing this error. I am hoping you might leave some clue why is the error happening. And I gladly introduce a PR to fix it.

Kjaer commented 3 years ago

I tracked down the cause of the error and attached the screenshots below, This is where the react-minisearch fails.

Screenshot 2020-12-27 at 3 03 04 PM
Screenshot 2020-12-27 at 3 03 22 PM
Screenshot 2020-12-27 at 3 03 39 PM

ReactCurrentDispatcher.current is null

lucaong commented 3 years ago

Hi @Kjaer , thanks for reporting this, I will have a look at it as soon as possible!

lucaong commented 3 years ago

It turns out, it's a problem with Rollup.js and local dependencies (using file: in package.json). When released, it works properly (in fact, the latest master was now released as v3.0.1).

I will try to report the problem to Rollup.js, even though it has surfaced already in a few issues posted in the past.

Thanks again for reporting!