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

Implementing Stoplight Search React Component Results in QueryClient Error #2569

Closed
dev-advocacy-qualtrics opened this issue Apr 16, 2024 · 4 comments

Comments

@dev-advocacy-qualtrics
Copy link

Implementing Stoplight Search React Component Results in QueryClient
QueryClient Error Stoplight Search
Error

Context

I am following this documentation to add Stoplight Elements Search to a React component on my web app.

Current Behavior

I keep seeing this error in the developer console when trying to render the component:

Uncaught (in promise) Error: No QueryClient set, use QueryClientProvider to set one

Expected Behavior

No QueryClient error gets thrown

Possible Workaround/Solution

I've looked online and it seems to stem from a react-query library, which has these posts about it. I tried implementing the changes mentioned in the Stack Overflow posts to no avail.

Steps to Reproduce

  1. Install the latest versions of Stoplight elements-core (8.1.1) and elements-dev-portal (2.1.3)
  2. Follow this documentation to implement the search functionality

Environment

"react": "^17.0.2",
"react-app-polyfill": "^2.0.0",
"react-dom": "^17.0.2",
"react-router-dom": "^5.3.4",
"@stoplight/elements-core": "8.1.1",
"@stoplight/elements-dev-portal": "2.1.3",
@dev-advocacy-qualtrics
Copy link
Author

dev-advocacy-qualtrics commented Apr 18, 2024

Here is the code I'm using:

import '@stoplight/elements-dev-portal/styles.min.css';
import { Search as ElementsSearch, useGetNodes, useGetWorkspace } from '@stoplight/elements-dev-portal';
import * as React from 'react';

const STOPLIGHT_TEST_ID = 'cHJqOjIzNzM0NQ';

export default function DocumentationLanding() {
  
  const StoplightSearch = ({ projectIds }) => {

    const [search, setSearch] = React.useState('');
    const [open, setOpen] = React.useState(false);
    const { data } = useGetNodes({
      search,
      projectIds,
    });
    const { data: workspace } = useGetWorkspace({
      projectIds,
    });
  
    const handleClose = () => {
      setOpen(false);
      setSearch('');
    };
  
    const handleClick = (data) => {
      window.location.href = `https://${workspace?.workspace.slug}.stoplight.io/docs/${data.project_slug}${data.uri}`;
    };
  
    return (
      <>
          <input placeholder="Search..." style={{ color: 'white' }} onFocus={() => setOpen(true)} />
          <ElementsSearch
              search={search}
              onSearch={setSearch}
              onClick={handleClick}
              onClose={handleClose}
              isOpen={open}
              searchResults={data}
          />
      </>
    );
  };
  
  return (
    <StoplightSearch projectIds={[STOPLIGHT_TEST_ID]}  />
  );
}

Copy link

This ticket has been labeled jira. A tracking ticket in Stoplight's Jira (STOP-478) has been created.

@dev-advocacy-qualtrics
Copy link
Author

This is pretty much a copy/pasta from this documentation page, so the likely culprit to me seems to be a dependency issue since the error seems to stem from a 3rd-party library.

@mnaumanali94
Copy link
Contributor

This issue was occurring because searchComponent was not wrapped inside DevPortalProvider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants