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

Bug: "Should have a queue. This is likely a bug in React" #30038

Closed
Nantris opened this issue Jun 21, 2024 · 11 comments
Closed

Bug: "Should have a queue. This is likely a bug in React" #30038

Nantris opened this issue Jun 21, 2024 · 11 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@Nantris
Copy link

Nantris commented Jun 21, 2024

React version: 18.2.0

(18.2.0 is required by Expo, but theoretically equivalent to 18.3.1 for this purpose)

Steps To Reproduce

  1. Unknown. No rules of hooks are being broken and the error stack is not helpful for diagnosis.

Code example:

I don't know how to reproduce this. Originally I faced #22049, supposedly caused by our "problem hook":

// Supposed problem hook
const linkableRef = useRef(linkable);
useEffect(() => {
  linkableRef.current = linkable; // linkable is an array of objects
  const { current: editor } = editorRef;
  if (editor) editor.commands.updateLinkable();
}, [linkable, editorRef]);

and removing the hook causes this instead: Error: Should have a queue. This is likely a bug in React. Please file an issue.

The current behavior

Using our simple hook causes #22049 - and removing our hook causes this issue instead

The expected behavior

Using React as specified in the docs causes no errors

@Nantris
Copy link
Author

Nantris commented Jun 22, 2024

This occurs ONLY on the first instance of taking the "problematic action" that causes the bug, and only if take on the the first mount of the problem component.

Identical actions after this crash has occurred and the component is re-mounted via the ErrorBoundary will not produce any errors. Loading the component a second time (different props of the same sort) also prevents this issue from occurring.

This extremely strange circumstance is making debugging unrelated issues quite difficult.

@Nantris
Copy link
Author

Nantris commented Jun 23, 2024

This is really plaguing us. I hope this can be resolved.

@Nantris
Copy link
Author

Nantris commented Jun 25, 2024

Friendly bump. I know this seems like impatience but an unmitigatable bug in React is a big problem for us.

@eps1lon
Copy link
Collaborator

eps1lon commented Jun 26, 2024

Calling hooks conditionally usually leads to these kind of bugs. If you want help fixing this issue, we need a minimal reproduction.

@Nantris
Copy link
Author

Nantris commented Jun 26, 2024

Thanks for your reply @eps1lon. We're 100% not calling hooks conditionally. I manually reviewed the code three times, asked ChatGPT, and ESLint also agrees. Unfortunately I have no idea what code is really causing the problem because commenting out the "problem hook" is what leads to this error. How can I glean any clue about the underlying cause?

I can't share our private code and the error message provides not a single avenue to pursue. It would be a different thing if I knew commenting out some code resolved an issue - but in this case it causes the issue.

@eps1lon
Copy link
Collaborator

eps1lon commented Jun 26, 2024

I'd start by removing surrounding code until it no longer reproduces. It might also be a sibling or parent component that calls hooks conditionally.

@Nantris
Copy link
Author

Nantris commented Jun 27, 2024

Thanks for the advice @eps1lon! I'll see if I can uncover anything.

@Nantris
Copy link
Author

Nantris commented Jul 18, 2024

@eps1lon:

Results in error: should have queue:

export const useEditExploreCapabilities = ({
  noEdits,
  isHashtag,
}) => {
  const [canEdit, setCanEdit] = useState(!noEdits && !isHashtag);
  const [canExplore, setCanExplore] = useState(canEdit);
  
  useEffect(() => {
    setCanEdit(noEdits && !isHashtag);
  }, [noEdits, isHashtag]);

  useEffect(() => {
    setCanExplore(canEdit || (isHashtag));
  }, [isHashtag, canEdit]);

  return [canEdit, canExplore];
};

Works fine:

export const useEditExploreCapabilities = ({
  noEdits,
  isHashtag
}) => {
  const [canEdit, setCanEdit] = useState(!noEdits && !isHashtag);
  const [canExplore, setCanExplore] = useState(canEdit);

  useEffect(() => {
    setCanEdit(!noEdits && !isHashtag);
    setCanExplore(canEdit || (isHashtag));
  }, [noEdits, isHashtag, canEdit]);

  return [canEdit, canExplore];
};

Is this expected? As far as I'm aware my original code didn't break any rules of hooks and seems, on the surface, more correct to me.

@eps1lon
Copy link
Collaborator

eps1lon commented Jul 19, 2024

I can't repro this in isolation: https://codesandbox.io/p/sandbox/cranky-currying-gn777q-gn777q

Maybe another component in your tree is violating Rule of React? For minimal reproductions, try to remove as much as possible from the whole component tree.

@Nantris
Copy link
Author

Nantris commented Jul 19, 2024

I am quite certain no rules of React (most especially rules of hooks) are being broken. ESLint agrees. I'm the only developer.

Since I have found a workaround I won't have time to work on this, but despite the inability to reproduce it in isolation, I feel confident this is a bug in React. The fact it was masked under other React errors further bolsters my belief.

@Nantris
Copy link
Author

Nantris commented Jul 19, 2024

For what it's worth, this is inside StrictMode, but adding that to your repro didn't change anything.

@Nantris Nantris closed this as completed Jul 28, 2024
@Nantris Nantris closed this as not planned Won't fix, can't repro, duplicate, stale Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

2 participants