Ajax form add library on callback I'm having an AJAX form, which on submit fires a callback function where I want to attach my library.
Here's the submit button:
$form['actions']['submit'] = [
    '#type' =&gt; 'submit',
    '#value' =&gt; 'Submit',
    '#button_type' =&gt; 'primary',
    '#name' =&gt; 'calculate',
    '#submit' =&gt; ['::submitForm'],
    '#ajax' =&gt; [
      'callback' =&gt; [$this, 'submitFormCallback'],
      'wrapper' =&gt; 'my-form-id',
    ],
];

When the submitFormCallback is called I attach my library using AjaxResponse and its addAttachments like this:
$ajax_response-&gt;addAttachments([
  'library' =&gt; ['my_module/library_name']
]);

The problem is when the AJAX is completed the whole page's layout is destroyed. When I do NOT attach the library to AJAX response everything seems to work fine. (I've already tried to empty my JS files in my_module/library_name so the javascript won't affect any DOM elements, but the result is the same.
Is there any problem with the way I attach the library to AjaxResponse that may cause the broken layout?
Is there any problem with the way I attach the library to AjaxResponse
that may cause the broken layout?

I guess so. This is how core does it when its an AJAX response, it attaches it to the form like this:
$form['#attached']['library'][] = 'my_module/library_name';
$ajax_response-&gt;setAttachments($form['#attached']);