Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppShell Suspense error #5979

Closed
1 of 2 tasks
uglyDrusLee opened this issue Mar 25, 2024 · 7 comments
Closed
1 of 2 tasks

AppShell Suspense error #5979

uglyDrusLee opened this issue Mar 25, 2024 · 7 comments
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)

Comments

@uglyDrusLee
Copy link

Dependencies check up

  • I have verified that I use latest version of all @mantine/* packages

What version of @mantine/* packages do you have in package.json?

7.6.2

What package has an issue?

@mantine/core

What framework do you use?

Vite

In which browsers you can reproduce the issue?

Chrome

Describe the bug

AppShell has useResizing, which leads to rerendering, due to setState inside useIsomorphicEffect. Because of this behavior - when hydrating, react throws an error "Uncaught Error: This Suspense boundary received an update before it finished hydrating".

If possible, include a link to a codesandbox with a minimal reproduction

No response

Possible fix

Consider wrapping setState inside startTransition, or at least provide an option to disable useResizing. This could be particularly useful when transitionDuration is set to 0.

Self-service

  • I would be willing to implement a fix for this issue
@rtivital
Copy link
Member

Please provide a repository with a minimal reproduction.

@uglyDrusLee
Copy link
Author

https://github.com/uglyDrusLee/drusMantineAppShellIssue/tree/main/
here's minimal reproduction. to start, just "npm run start". server will be started on 3000 port.

@rtivital
Copy link
Member

The issue is not related to use-resizing. If the code is chaged to

import { startTransition, useRef, useState } from 'react';
import { useIsomorphicEffect, useWindowEvent } from '@mantine/hooks';

interface UseResizingInput {
  transitionDuration: number | undefined;
  disabled: boolean | undefined;
}

export function useResizing({ transitionDuration, disabled }: UseResizingInput) {
  const [resizing, setResizing] = useState(true);
  const resizingTimeout = useRef<number>();
  const disabledTimeout = useRef<number>();

  useWindowEvent('resize', () => {
    setResizing(true);
    clearTimeout(resizingTimeout.current);
    resizingTimeout.current = window.setTimeout(() => setResizing(false), 200);
  });

  useIsomorphicEffect(() => {
    startTransition(() => {
      setResizing(true);
      clearTimeout(disabledTimeout.current);
      disabledTimeout.current = window.setTimeout(
        () => setResizing(false),
        transitionDuration || 0
      );
    });
  }, [disabled, transitionDuration]);

  return resizing;
}

Or resizing removed entirely, it does not fix the error message.

You are welcome to research the issue and propose the fix.

@rtivital rtivital added the help wanted Contributions from community are welcome label Mar 26, 2024
@rtivital rtivital changed the title AppShell unnecessary rerenders AppShell Suspense error Mar 26, 2024
@uglyDrusLee
Copy link
Author

your solution works fine for me, error is gone. maybe you faced vite's cache? to get rid of it you can just delete ".vite" folder inside node_modules, restart "npm run start". dont know how exactly you tested with my repo. i just manually edit useResizing inside node_modules and error is gone.

@rtivital rtivital removed the help wanted Contributions from community are welcome label Mar 26, 2024
@rtivital
Copy link
Member

All right, then I'll just add this solution in next patch

@rtivital rtivital added the Fixed patch Completed issues that will be published with next patch (1.0.X) label Mar 26, 2024
@uglyDrusLee
Copy link
Author

thank you very much

@rtivital
Copy link
Member

Fixed in 7.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)
Projects
None yet
Development

No branches or pull requests

2 participants