Comments (5)
Same issue for me as well. Also I noticed that if I make a change in the file where I have useReactDetector and nextjs dev server reloads on its own, then useReactDetector works and returns width. But when I then try to manually refresh or load the page it returns undefined every time. Like OP said this only happens in NextJS 14.0.2+, when I use 14.0.1 everything works.
from react-resize-detector.
I'm having the same issue as well, I'm using Next.js 14.0.3. I had to downgrade my Next.js project to 14.0.1 and it worked like a charm.
from react-resize-detector.
I've already opened an issue at nextjs vercel/next.js#58767
I have already debugged it a bit, here are my findings:
- it was introduced by a commit in nextjs which pulled react changes
- it is caused by the react strict mode, but only since nextjs
v14.0.2
, disabling it solves the problem or the prod build - you can quick fix it in react-resize-detector by commenting this out:
return () => {
// component is unmounted
// clear ref to avoid memory leaks
// setRefElement(null); // <= comment to quick-fix it
onRefChange.current = null;
};
- It also seems that since
v14.0.2
thesetRefElement
function is only called twice. The first time it sets the ref right, the second time it sets the ref tonull
, triggered by the code above. That's why commenting out that line works, because it can't set the ref tonull
. - In
v14.0.1
this function is called at least 3 or 4 times, I can't remember. But the important thing is that after setting it tonull
the second time, it gets set correctly the third time.
As a side note I am pretty new to the hole JS/TS ecosystem so I don't fully understand all of it, but that's are my findings. I hope they might help.
from react-resize-detector.
In version 9.1.1:
React's strict mode causes components to render twice in development, as described here: React StrictMode Documentation. This also means that the logic for mounting and unmounting in useEffect
is executed twice.
However, there's an issue with ref
callbacks: they are only triggered once before the first unmount. As a result, it's not possible to remove the reference to the DOM node during unmount because the reference is no longer accessible afterward.
During my tests, I observed no memory leaks even after removing part of the unmount logic. We still maintain the "observer" cleanup, and React handles the removal of DOM references from the state.
Please upgrade to version 9.1.1 and inform me if any issues persist.
from react-resize-detector.
@maslianok Please, take a look when you have time
from react-resize-detector.
Related Issues (20)
- `onFinishResize`? HOT 2
- Allow React 18 as peerDependency HOT 10
- ReactResizeDetector Component is not working with React18 HOT 1
- Wrong build folder in NPM packages 7.1.1 and 7.0.2 HOT 2
- react resize hook doesn't detect vertical resize HOT 1
- TypeError: window.ResizeObserver is not a constructor HOT 3
- Return width according to provided observerOptions HOT 4
- SourceMap loader complains "Missing source files" in the new v8 build HOT 12
- Debug `console.log` shows up in the code published to NPM HOT 4
- useResizeDetector targetRef cannot be null TS2322 HOT 5
- React errors in DEV mode HOT 12
- useResizeDetector returns width = undefined using forwardRef HOT 10
- dont'work with ReactjS scheduler
- ResizeObserver loop limit exceeded in v9.1.0 HOT 6
- (Request) pass ref to callback HOT 4
- onResize doesn't work when min-height is set HOT 4
- Package not compatible with Edge Functions HOT 4
- Best practice for using react-resize-detector v10 in class components HOT 2
- Incorrect peer dependencies HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-resize-detector.