hexlet-correction icon indicating copy to clipboard operation
hexlet-correction copied to clipboard

Bug: The script is loaded before the DOM is built

Open SamIvan-ark opened this issue 1 year ago • 6 comments

Summary

The script loads before building the DOM and crushes when it tries to find the body. Initial scripts for embedding TR:

<script src="https://cdn.jsdelivr.net/gh/hexlet/hexlet-correction@main/src/widget/index.js"></script>
<script>
    handleTypoReporter({ authorizationToken: 'MzAyOmQ2ZTI5ZTBhLTRkMmUtNGFlOS05MzQ2LTY4NTFlMzUwY2ZhYQ==',
    workSpaceUrl: 'https://hexlet-correction.herokuapp.com', workSpaceId: '302'})
</script>

The problem was solved by adding an event that the DOM is ready:

<script src="https://cdn.jsdelivr.net/gh/hexlet/hexlet-correction@main/src/widget/index.js"></script>
<script>
  document.addEventListener('DOMContentLoaded', function() {
    handleTypoReporter({ authorizationToken: 'MzAyOmQ2ZTI5ZTBhLTRkMmUtNGFlOS05MzQ2LTY4NTFlMzUwY2ZhYQ==',
    workSpaceUrl: 'https://hexlet-correction.herokuapp.com', workSpaceId: '302'})
});
</script>

Reproduction steps

1. Insert the script into the head
2. Open the console
3. See the error that body === null

Expected result

The typo reporter element appears on the page

Actual result

The element is not present, there is an error in the console:

index.js:176 Uncaught TypeError: Cannot read properties of null (reading 'append')
    at generateModal (index.js:176:8)
    at handleTypoReporter (index.js:277:20)

Browsers

Chrome

OS

No response

SamIvan-ark avatar Aug 31 '23 12:08 SamIvan-ark

@Mari-Krukovskaya можете взять в работу. Тут задача не совсем фронтендовая - она скорее на стыке. Нужно проверить, что новый сниппет будет ОК работать и поменять код сниппета в шаблоне страницы. Сам шаблон страницы написан на Java, но я думаю, что сможете разобраться

fey avatar Dec 20 '23 14:12 fey

Актуально и выглядит несложно.

fey avatar Mar 11 '24 13:03 fey

Взяли в работу ?

amirhraj avatar Mar 11 '24 17:03 amirhraj

@amirhraj берите)

fey avatar Mar 11 '24 17:03 fey

взял в работу

amirhraj avatar Mar 11 '24 18:03 amirhraj

Задача актуальна.

fey avatar Apr 15 '24 12:04 fey