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

Improve SupportError when document.body is not set #4394

Merged
merged 1 commit into from
Oct 27, 2023

Conversation

colinrotherham
Copy link
Contributor

@colinrotherham colinrotherham commented Oct 27, 2023

This PR addresses feedback from #4389 (comment)

Running initAll() in <head> currently throws an error because document.body is null 🔥

<head>
  <!-- // ... -->
  <script src="/javascripts/all.bundle.js"></script>
  <script>
    window.GOVUKFrontend.initAll()
  </script>
</head>

But even if we fix this to guard document.body we'd incorrectly log to the console:

GOV.UK Frontend is not supported in this browser

Additionally, we may want to catch null element property access before our users do in:

Informing users that forget type="module"

Either way, we should fix this issue so users realise when they run initAll() too early

This PR clarifies the SupportError text to do this:

$scope
  ? 'GOV.UK Frontend is not supported in this browser'
  : 'GOV.UK Frontend initialised without `<script type="module">`'

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4394 October 27, 2023 12:51 Inactive
@colinrotherham colinrotherham added 🐛 bug Something isn't working the way it should (including incorrect wording in documentation) javascript labels Oct 27, 2023
@colinrotherham colinrotherham added this to the v5.0 milestone Oct 27, 2023
@github-actions
Copy link

github-actions bot commented Oct 27, 2023

📋 Stats

File sizes

File Size
dist/govuk-frontend-5.0.0-beta.0.min.css 114 KiB
dist/govuk-frontend-5.0.0-beta.0.min.js 37.85 KiB
packages/govuk-frontend/dist/govuk/all.bundle.js 77.08 KiB
packages/govuk-frontend/dist/govuk/all.bundle.mjs 72.37 KiB
packages/govuk-frontend/dist/govuk/all.mjs 3.8 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs 359 B
packages/govuk-frontend/dist/govuk/govuk-frontend.min.css 113.99 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend.min.js 37.92 KiB
packages/govuk-frontend/dist/govuk/i18n.mjs 5.3 KiB

Modules

File Size
all.mjs 68.7 KiB
components/accordion/accordion.mjs 21.35 KiB
components/button/button.mjs 4.48 KiB
components/character-count/character-count.mjs 20.79 KiB
components/checkboxes/checkboxes.mjs 5.61 KiB
components/error-summary/error-summary.mjs 5.79 KiB
components/exit-this-page/exit-this-page.mjs 15.79 KiB
components/header/header.mjs 3.68 KiB
components/notification-banner/notification-banner.mjs 4.32 KiB
components/radios/radios.mjs 4.6 KiB
components/skip-link/skip-link.mjs 3.6 KiB
components/tabs/tabs.mjs 9.37 KiB

View stats and visualisations on the review app


Action run for b90b303

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4394 October 27, 2023 15:48 Inactive
Copy link
Member

@romaricpascal romaricpascal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛵ ⛵ Thanks for tweaking the wording.

Typically we’d only expect a null `document.body` for classic `<script>` tags without `type="module"` when loaded via `<head>`
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4394 October 27, 2023 16:02 Inactive
@colinrotherham colinrotherham merged commit b4daaab into main Oct 27, 2023
43 checks passed
@colinrotherham colinrotherham deleted the support-error-body branch October 27, 2023 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working the way it should (including incorrect wording in documentation) javascript
Projects
Development

Successfully merging this pull request may close these issues.

3 participants