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

Add polyfill for String.prototype.trim #2908

Merged
merged 1 commit into from
Oct 11, 2022
Merged

Conversation

36degrees
Copy link
Contributor

@36degrees 36degrees commented Oct 10, 2022

In bc843a3 (#2840) we introduced a new normaliseString helper method which relies on String.prototype.trim, which is not supported in IE8 or IE9.

This causes a script error when going to any page in the review app (in IE8) which contains a component that accepts config via data attributes.

Add a polyfill for String.prototype.trim based on the polyfill that used to be on MDN (before they removed content relating to IE8), adapted to match the format used for the existing polyfills.

Closes #2903.

In bc843a3 (#2840) we introduced a new `normaliseString` helper method [1] which relies on `String.prototype.trim` [2], which is not supported in IE8 or IE9 [3]

This causes a script error when going to any page in the review app (in IE8) which contains a component that accepts config via data attributes.

Add a polyfill for String.prototype.trim based on the polyfill that used to be on MDN [4] (before they removed content relating to IE8), adapted to match the format used for the existing polyfills.

[1]: https://github.com/alphagov/govuk-frontend/blob/cf7b06ceb19236a9afeb5399158b35391219cf99/src/govuk/common.mjs#L152
[2]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim
[3]: https://caniuse.com/mdn-javascript_builtins_string_trim
[4]: https://github.com/mdn/content/blob/cf607d68522cd35ee7670782d3ee3a361eaef2e4/files/en-us/web/javascript/reference/global_objects/string/trim/index.md#polyfill
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2908 October 10, 2022 15:38 Inactive
Copy link
Contributor

@colinrotherham colinrotherham left a comment

Choose a reason for hiding this comment

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

Approving, but subject to us updating the sideEffects package field

@36degrees
Copy link
Contributor Author

Approving, but subject to us updating the sideEffects package field

To summarise a conversation on Slack:

  • the issue we're concerned about is that e.g. someone importing e.g. { nodeListForEach } from 'govuk-frontend/package/govuk-esm/common.mjs gets the polyfills 'unsolicited' as side-effects when they don't want or need them
  • we think that govuk-esm/vendor being listed in sideEffects should mean that a bundler would understand that because common.mjs imports from vendor it also has side effects, but are concerned that not all bundlers would do this
  • we think a better solution is to avoid importing polyfills from common.mjs, which we're planning to do explore as part of Limit side effects of polyfills loaded for config/I18n #2907 – I've attached that issue to the [NEXT] milestone to make sure that we actually do it!
  • therefore we're going to merge this as-is and revisit as part of that issue before we release

@36degrees 36degrees merged commit eebe25f into main Oct 11, 2022
@36degrees 36degrees deleted the string-trim-polyfill branch October 11, 2022 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The normaliseData function uses String.trim which is not supported in IE8/IE9
3 participants