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

Bug: The script is loaded before the DOM is built #201

Open
SamIvan-ark opened this issue Aug 31, 2023 · 6 comments
Open

Bug: The script is loaded before the DOM is built #201

SamIvan-ark opened this issue Aug 31, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@SamIvan-ark
Copy link

SamIvan-ark commented Aug 31, 2023

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 SamIvan-ark added the bug Something isn't working label Aug 31, 2023
@fey
Copy link
Collaborator

fey commented Dec 20, 2023

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

@fey
Copy link
Collaborator

fey commented Mar 11, 2024

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

@amirhraj
Copy link

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

@fey
Copy link
Collaborator

fey commented Mar 11, 2024

@amirhraj берите)

@amirhraj
Copy link

взял в работу

@fey
Copy link
Collaborator

fey commented Apr 15, 2024

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

@niyatanya niyatanya changed the title Bug: Скрипт загружается до построения DOM Bug: The script is loaded before the DOM is built Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants