Skip to content

Fix React's development StrictMode rendering - #147

Merged
gmunoz merged 1 commit into
masterfrom
fix-dev-render-small-1x1-pixel
Sep 30, 2026
Merged

gmunoz merged 1 commit into
masterfrom
fix-dev-render-small-1x1-pixel

Conversation

@gmunoz

@gmunoz gmunoz commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Fixes a bug in use-resize-observer that would ignore resize updates when using React 18's development StrictMode behavior. This is not typically a feature seen in prod deployments.

Removes resize-observer and will use the browser's native ResizeObserver behavior.

Fixes #146

Fixes a bug in use-resize-observer that would ignore resize updates when
using React 18's develepment StrictMode behavior. This is not typically
a feature seen in prod deployments.

Removes resize-observer and will use the browser's native ResizeObserver
behavior.

Fixes #146
@gmunoz

gmunoz commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

I opt'ed for a module bump here. The only changes we need from the module should be:

  --- a/node_modules/use-resize-observer/dist/bundle.esm.js
  +++ b/node_modules/use-resize-observer/dist/bundle.esm.js
  @@
   var didUnmount = useRef(false);
   useEffect(function () {
  +  didUnmount.current = false;
     return function () {
       didUnmount.current = true;
     };
   }, []);

But, if we do need to revert it may be possible to workaround with code. However, I'd prefer to roll forward when possible. E.g.

  import { useCallback, useEffect, useRef, useState } from 'react';
  import useResizeObserverV7 from 'use-resize-observer';

  export default function useResizeObserver() {
      const mounted = useRef(false);
      const [size, setSize] = useState({ width: 1, height: 1 });

      useEffect(() => {
          mounted.current = true;
          return () => {
              mounted.current = false;
          };
      }, []);

      const onResize = useCallback((nextSize) => {
          if (mounted.current) {
              setSize(nextSize);
          }
      }, []);

      const { ref } = useResizeObserverV7({ onResize });

      return { ref, ...size };
  }

@gmunoz
gmunoz merged commit 2eca1b6 into master Sep 30, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Front-end may render a 1x1 pixel flame graph

2 participants