alphagov / govuk-prototype-kit

Rapidly create HTML prototypes of GOV.UK services
https://prototype-kit.service.gov.uk
MIT License
301 stars 236 forks source link

Fix error server `/manage-prototype/dependencies` #2333

Closed colinrotherham closed 1 year ago

colinrotherham commented 1 year ago

This PR fixes a few error page issues

It picks up from changes to isolate GOV.UK Frontend versions in:

Sass variables

The error page Sass $govuk-assets-path uses /manage-prototype/dependencies/govuk-frontend but we didn't handle error server responses for this route so fonts and background images were missing:

https://github.com/alphagov/govuk-prototype-kit/blob/86fb72a0290af1896dce34472732a778711f6072/lib/assets/sass/manage-prototype.scss#L1

Fonts missing Fonts missing, errors

Nunjucks assets

The error page Nunjucks assetPath uses /plugin-assets/govuk-frontend which would typically route to a plugin version of GOV.UK Frontend rather than one internal to the Prototype Kit

This was handled but with different URLs to the CSS:

<link rel="shortcut icon" sizes="16x16 32x32 48x48" href="/plugin-assets/govuk-frontend/govuk/assets/images/favicon.ico" type="image/x-icon">
<link rel="mask-icon" href="/plugin-assets/govuk-frontend/govuk/assets/images/govuk-mask-icon.svg" color="#0b0c0c">

https://github.com/alphagov/govuk-prototype-kit/blob/d262239d601e92cc7af138fcf94c7a26172e6bd2/lib/errorServer.js#L59-L61

Sass variables

The error page shares the manage-prototype.scss stylesheet which is hard coded to use:

https://github.com/alphagov/govuk-prototype-kit/blob/86fb72a0290af1896dce34472732a778711f6072/lib/assets/sass/manage-prototype.scss#L1

HTTP content-type headers

GOV.UK Frontend includes fonts (*.woff, *.woff2), images (*.png, *.svg) and favicons (*.ico)

These have now been added to the error server including *.mjs with the old-but-new text/javascript type

https://github.com/alphagov/govuk-prototype-kit/blob/86fb72a0290af1896dce34472732a778711f6072/lib/errorServer.js#L27-L30

Legacy GOV.UK Frontend

The Prototype Kit currently patches versions of GOV.UK Frontend prior to v4.4.0 (where nunjucksMacros and sass fields were added to the plugin config) but the $govuk-assets-path variable was missing leaving the default as:

$govuk-assets-path: '/govuk/assets/';
colinrotherham commented 1 year ago

To confirm it works, this error is back on Manage prototype pages:

The kit must be running govuk-frontend@4.5.0 internally?

It's fixed on plugin pages which appear to use govuk-frontend@4.7.0

nataliecarey commented 1 year ago

Historically we've tested the isolation by trying scenarios where:

colinrotherham commented 1 year ago

In that scenario the kit fails to start both in main and in error-server-assets.

Happy to accept a challenge, but some of your tests need govuk-frontend installed

Is running without GOV.UK Frontend entirely more for this one?

colinrotherham commented 1 year ago

Thanks @nataliecarey

Just a reminder that you'll now see GOV.UK Frontend v4.5.0 internally due to --save-exact

https://github.com/alphagov/govuk-prototype-kit/blob/86fb72a0290af1896dce34472732a778711f6072/package.json#L75

Prototype pages using plugin assets won't be affected

Would be good to do another PR to avoid the source map 404 issue https://github.com/alphagov/govuk-prototype-kit/pull/2333#issuecomment-1719458377