Skip to content

Conversation

@claudio-ferraro
Copy link

Description

Fixes a TypeError that occurs when the #form-validate element doesn't exist in the DOM when the autofill template tries to append the block loader element.

Problem

The code was attempting to call appendChild() directly on the result of querySelector('#form-validate') without checking if the element exists. This caused crashes on the customer address edit page in certain scenarios (e.g., when using Hyvä theme or when the form hasn't been rendered yet).

Error:

TypeError: null is not an object (evaluating 'document.querySelector('#form-validate').appendChild')

Solution

  • Added DOMContentLoaded event listener to ensure the DOM is fully loaded before manipulating elements
  • Added null checks for both #form-validate and #block-loader-customer-address elements before attempting the append operation
  • Only performs appendChild() when both elements exist

Impact

This is a defensive fix that prevents crashes without changing existing functionality when elements are present.

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.

1 participant