Javascript Loading Error

Created on 7 May 2024, about 2 months ago

Problem/Motivation

When loading pages that utilize the yext_search module, an intermittent JavaScript error occurs in the console, which affects the functionality of the search feature. The error is as follows:

Uncaught ReferenceError: initAnswers is not defined
    at HTMLScriptElement.onload ((index):28:133)

This error suggests that the JavaScript function initAnswers is being called before it is fully defined, likely due to the script loading asynchronously.

Steps to Reproduce

  1. Visit any page on the site where yext_search module is enabled and the initAnswers function is required.
  2. Refresh the page multiple times (the issue may not occur on every page load due to its asynchronous nature).

Proposed Resolution

Change the JavaScript loading behavior in yext_search.module to load the script synchronously instead of asynchronously. This can be done by setting the async attribute to false for the script that loads initAnswers.

Remaining tasks

  • Confirm the issue consistently reproduces as described.
  • Adjust the script tag settings in the module.
  • Test to ensure the error no longer occurs.
  • Review by module maintainers.

User interface changes

None. This change does not alter the user interface but affects the loading behavior of JavaScript resources.

API changes

None. There are no changes to the APIs; this is purely a front-end performance enhancement.

Data model changes

None. No data model changes are required for this fix.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024