Q embedded searchbar not rendering anymore

Hi,
We’ve had q search bar embedded in our app for a few years. It worked great and nothing in our code has changed since we did the work to embed it.
A few days ago the bar stopped showing. If I open the url in another tab the q search bar shows correctly. But embedding it is not working.

I am out of ideas on how to solve this sudden issue, any help would be greatly appreciated.
Thanks

Edit: I finally found an error, though not very helpful still
amazon_quicksight_embedding_sdk__WEBPACK_IMPORTED_MODULE_1__.embedQSearchBar is not a function

Hello @esther.han !

That’s pretty interesting. Does this fail if you retry the deployment for embedding in your application?

I would also double check that it has nothing to do with the issue outlined here:

Thank you for your answer @duncan.
Yes, it does keep failing. It seems embedQSearchBar is not available anymore. Is it deprecated or something?

Hey @esther.han !

You should be able to embed the Q Search bar, can you share an anonymized version of your code?

This will help me understand if there is something specific that is wrong or needs to be updated.

Hello @esther.han ,

Are you able to share an anonymized view of the code that you are using to embed the Q Search bar?

Thank you for your help @duncan.

This is the react component that call for the embed q search bar:
import React, { useState, useEffect, useRef } from ‘react’;
import { embedQSearchBar } from ‘amazon-quicksight-embedding-sdk’;

import { useGetQsSearchbarUrlQuery } from ‘services/nextgen’;

import { useLocalization } from ‘features/localization/localizationSlice’;
import { useCurrentCompany } from ‘features/company/companySlice’;

import styles from ‘./Insights.module.scss’;

const Searchbar = () => {
const localization = useLocalization();
const searchbarContainerRef = useRef(null);
const searchbarFrameRef = useRef(null);
const currentCompany = useCurrentCompany();
const searchbarUrl = useGetQsSearchbarUrlQuery({ companyId: currentCompany.id });

const [qSession, setQSession] = useState();

const onLoad = () => {
// console.debug(‘searchbar - onLoad’);
searchbarContainerRef.current.style.display = ‘block’;
setTimeout(() => {
searchbarContainerRef.current.style.height = ‘80px’;
}, 10);
setTimeout(() => {
searchbarFrameRef.current.style.height = ‘80px’;
searchbarFrameRef.current.style.opacity = 1;
}, 100);
};

const onError = payload => {
// console.debug(‘searchbar - onError’, payload);
searchbarContainerRef.current.style.display = ‘none’;
searchbarContainerRef.current.style.height = ‘0px’;
searchbarFrameRef.current.style.opacity = 0;
};

const onOpen = () => {
// console.debug(‘searchbar - onOpen’);
};

const onClose = () => {
// console.debug(‘searchbar - onClose’);
searchbarFrameRef.current.style.height = ‘80px’;
};

useEffect(() => {
// console.debug(‘searchbar - currentCompany change’);
setQSession();
}, [currentCompany]);

useEffect(() => {
const frameDiv = searchbarFrameRef.current;

if (!qSession && frameDiv && searchbarUrl.data) {
  const options = {
    url: searchbarUrl.data,
    container: frameDiv,
    locale: localization.locale,
    width: '100%',
    qSearchBarOptions: {
      iconDisabled: true,
      topicNameDisabled: false,
      allowTopicSelection: true,
      maxHeightForQ: '500px'
    }
  };
  const session = embedQSearchBar(options);
  session.on('load', onLoad);
  session.on('error', onError);
  session.on('open', onOpen);
  session.on('close', onClose);
  setQSession(session);
  // console.debug('searchbar - embed sdk - after', { searchbarUrl, session, options });
}

}, [searchbarFrameRef, searchbarUrl]);

return (

  <div className={styles.searchbarContainer} ref={searchbarContainerRef}>
    <div className={styles.searchbarFrame} ref={searchbarFrameRef} />
  </div>

);
};

export default Searchbar;

We are using generateEmbedUrlForRegisteredUser to get the url.

We set breakpoints when we get the url to open the url in a separate tab. Sometimes it works and some other times this error gets displayed

My coworker was suspecting that something is happening with the session. We are passing a 600min session lifetime, and nothing has changed in our side for a few years.
We are still using sdk 1.0. I updated to sdk 2 and changed the necessary code but the same issue is happening

Hello @esther.han !

I would follow the guide here:

@duncan that is the first troubleshoot step I did, update to latest sdk and follow that example, but it is still not working

import React, { useState, useEffect, useRef } from ‘react’;
import QuickSightEmbedding from ‘amazon-quicksight-embedding-sdk’;

import { useGetQsSearchbarUrlQuery } from ‘services/nextgen’;

import { useLocalization } from ‘features/localization/localizationSlice’;
import { Can, services } from ‘features/permissions’;
import { useCurrentCompany } from ‘features/company/companySlice’;

import styles from ‘./Insights.module.scss’;

const Searchbar = () => {
const localization = useLocalization();
const searchbarContainerRef = useRef(null);
const searchbarFrameRef = useRef(null);
const currentCompany = useCurrentCompany();
const searchbarUrl = useGetQsSearchbarUrlQuery({ companyId: currentCompany.id });

const [qSession, setQSession] = useState(null);
const [embedQSearchBar, setEmbedQSearchBar] = useState(null);

const onLoad = () => {
// console.debug(‘searchbar - onLoad’);
searchbarContainerRef.current.style.display = ‘block’;
setTimeout(() => {
searchbarContainerRef.current.style.height = ‘80px’;
}, 10);
setTimeout(() => {
searchbarFrameRef.current.style.height = ‘80px’;
searchbarFrameRef.current.style.opacity = 1;
}, 100);
};

const onError = payload => {
// console.debug(‘searchbar - onError’, payload);
//searchbarContainerRef.current.style.display = ‘none’;
//searchbarContainerRef.current.style.height = ‘0px’;
//searchbarFrameRef.current.style.opacity = 0;
};

const onOpen = () => {
// console.debug(‘searchbar - onOpen’);
};

const onClose = () => {
// console.debug(‘searchbar - onClose’);
searchbarFrameRef.current.style.height = ‘80px’;
};

useEffect(() => {
// console.debug(‘searchbar - currentCompany change’);
setQSession();
}, [currentCompany]);

useEffect(() => {
const initializeEmbeddingContext = async () => {
try {
const embeddingContext = await QuickSightEmbedding.createEmbeddingContext();
setEmbedQSearchBar(() => embeddingContext.embedQSearchBar);
console.log(‘Embedding context initialized:’, embeddingContext);
} catch (error) {
console.error(‘Error initializing embedding context:’, error);
}
};

initializeEmbeddingContext();

}, );

useEffect(() => {
const embedSearchbar = async () => {
if (!embedQSearchBar) {
return;
}

  const frameDiv = searchbarFrameRef.current;

  // console.debug('searchbar - embed sdk - before', { searchbarUrl, qSession, frameDiv });

  if (!qSession && frameDiv && searchbarUrl.data) {
    console.log('Embedding search bar with URL:', searchbarUrl.data);
    
    const options = {
      url: searchbarUrl.data,
      container: frameDiv,
      width: '100%',
      onLoad: onLoad,
      onError: onError,
      onOpen: onOpen,
      onClose: onClose, 
      onChange: (changeEvent, metadata) => {
        console.log('Qsearch option change:', changeEvent.eventName, metadata);
      },
    };

    const contentOptions = {
      locale: localization.locale || 'en-US',
      hideTopicName: false,
      allowTopicSelection: true,
      onMessage: async (messageEvent, experienceMetadata) => {
        console.log("Q Search Event:", messageEvent.eventName, experienceMetadata);
      }
    };

    try {
      const session = await embedQSearchBar(options, contentOptions);
      setQSession(session);
      console.log('Search bar embedded successfully:', session);
    } catch (error) {
      console.error('Error embedding QuickSight search bar:', error);
    }
  }
};

embedSearchbar();

}, [searchbarUrl.data, embedQSearchBar]); // Added dependencies

useEffect(() => {
setQSession(null);
}, [currentCompany]);

return (

  <div className={styles.searchbarContainer} ref={searchbarContainerRef}>
    <div className={styles.searchbarFrame} ref={searchbarFrameRef} />
  </div>

);
};

export default Searchbar;

Hey @esther.han

If you are following the the documentation and still running into the error then I recommend creating a support ticket with AWS.

Here are the steps to open a support case. If your company has someone who manages your AWS account, you might not have direct access to AWS Support and will need to raise an internal ticket to your IT team or whomever manages your AWS account. They should be able to open an AWS Support case on your behalf.

Hi @esther.han,
It’s been awhile since we last heard from you on this thread, did you have any additional questions regarding your post?

If we do not hear back within the next 3 business days, I’ll close out this topic.

Thank you!

Hey @Brett, my issue is not resolved, but as suggested by duncan I opened a support ticket that I am still waiting to get help with. Feel free to close this topic, thanks

1 Like