From 596c0b1ccc9d008bccdfaf644960dc4edc69b323 Mon Sep 17 00:00:00 2001 From: Romaric Pascal Date: Tue, 26 Sep 2023 17:52:44 +0100 Subject: [PATCH] Add explanation that individual initialisation will throw errors Co-authored-by: Colin Rotherham --- .../index.html.md.erb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/importing-css-assets-and-javascript/index.html.md.erb b/source/importing-css-assets-and-javascript/index.html.md.erb index 173b4cd0..3115a0d1 100644 --- a/source/importing-css-assets-and-javascript/index.html.md.erb +++ b/source/importing-css-assets-and-javascript/index.html.md.erb @@ -162,6 +162,14 @@ Then import the JavaScript file before the closing `` tag of your HTML pa ``` +Errors from components will be logged in the browser's console. + +For example, when: + +* GOV.UK Frontend is not supported in the current browser +* Component templates have missing changes from our release notes +* Component JavaScript configuration does not match our documentation + #### Select and initialise an individual component You can select and initialise a specific component by using its `data-module` attribute. For example, use `govuk-radios` to initialise the first radio component on a page: @@ -176,6 +184,13 @@ You can select and initialise a specific component by using its `data-module` at ``` +When initialised individually, components will throw errors if GOV.UK Frontend is not supported, some key markup is missing or their configuration is invalid. + +It's up to you to decide what to do with these errors and either: + + - let them break the flow of execution + - handle the errors with [a `try/catch` block](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch) + ### Import JavaScript using a bundler If you decide to import using a bundler, we recommend you use `import` to only import the JavaScript for components you're using in your service. For example: