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

fix: multiple surveys might be showing at the same time #2179

Merged
merged 1 commit into from
Mar 4, 2024

Conversation

mattinannt
Copy link
Member

What does this PR do?

fix: multiple surveys might be showing at the same time

Copy link

vercel bot commented Mar 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
formbricks-cloud ⬜️ Ignored (Inspect) Visit Preview Mar 4, 2024 11:11am
formbricks-com ⬜️ Ignored (Inspect) Visit Preview Mar 4, 2024 11:11am

Copy link
Contributor

github-actions bot commented Mar 4, 2024

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

packages/js/src/lib/widget.ts

The renderWidget function is quite long and complex. It would be beneficial to break it down into smaller, more manageable functions. This would make the code easier to read and maintain.
Create Issue
See the diff
Checkout the fix

    const setupProductOverwrites = (product, productOverwrites) => {
      const brandColor = productOverwrites.brandColor ?? product.brandColor;
      const highlightBorderColor = productOverwrites.highlightBorderColor ?? product.highlightBorderColor;
      const clickOutside = productOverwrites.clickOutsideClose ?? product.clickOutsideClose;
      const darkOverlay = productOverwrites.darkOverlay ?? product.darkOverlay;
      const placement = productOverwrites.placement ?? product.placement;
      const isBrandingEnabled = product.inAppSurveyBranding;
      
      return {brandColor, highlightBorderColor, clickOutside, darkOverlay, placement, isBrandingEnabled};
    }
    
    const handleOnDisplay = async (survey, surveyState, responseQueue) => {
      // existing onDisplay code...
    }
    
    const handleOnResponse = (responseUpdate, surveyState, responseQueue) => {
      // existing onResponse code...
    }
    
    const handleOnFileUpload = async (file, params) => {
      // existing onFileUpload code...
    }
    
    // In the main function
    const productOverwrites = setupProductOverwrites(product, survey.productOverwrites ?? {});
    handleOnDisplay(survey, surveyState, responseQueue);
    handleOnResponse(responseUpdate, surveyState, responseQueue);
    handleOnFileUpload(file, params);
git fetch origin && git checkout -b ReviewBot/Impro-wdli5d2 origin/ReviewBot/Impro-wdli5d2

The config.get() function is called multiple times within the renderWidget function. This could potentially slow down the execution of the function, especially if the config.get() function is expensive in terms of computational resources. It would be more efficient to call this function once at the beginning of the renderWidget function and store the result in a variable, which can then be used throughout the function.
Create Issue
See the diff
Checkout the fix

    const configData = config.get();
    const product = configData.state.product;
    const apiHost = configData.apiHost;
    const environmentId = configData.environmentId;
    const userId = configData.userId;
    // Use these variables instead of calling config.get() multiple times
git fetch origin && git checkout -b ReviewBot/Impro-3xi3mbe origin/ReviewBot/Impro-3xi3mbe

@mattinannt mattinannt added this pull request to the merge queue Mar 4, 2024
Merged via the queue into main with commit c5bdbc8 Mar 4, 2024
16 checks passed
@mattinannt mattinannt deleted the feature/fix-multi-survey-showing branch March 4, 2024 11:20
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.

None yet

1 participant