useSearchParam doesn't work in production build of create-react-app
What is the current behavior?
My project is created by create-react-app, I didn't change any of the configs and useSearchParam is the only hook that I imported from react-use.
In dev environment, everything works fine, but after I run a production build and test the output, it didn't work as the same as the dev environment, history.pushState(...) didn't trigger any events.
Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than react-use. Paste the link to your JSFiddle or CodeSandbox example below:
Not able to provide the code example in this case.
What is the expected behavior?
history.pushState(...) triggers the pushstate event on window.
I guess it's because the patch is not successfully loaded after production build, since
tree-shakingofWebpackis on by default anduseSearchParamis the only hook that I imported,useLocationdoesn't get into the bundle.
A little about versions:
- OS: macOS 10.14.6
- Browser (vendor and version): Chrome 93.0.4577.63 (Official Build) (x86_64)
- React: 17.0.2
react-use: 17.3.1- Did this worked in the previous package version? No.
Experiencing the same in next js v13 project. Everything is fine in dev mode, in production search stops being reactive, app does nothing when search string changes.