flexion / ef-cms

An Electronic Filing / Case Management System.
24 stars 10 forks source link

Upgrade USWDS to 3.8.0 #10333

Open TomElliottFlexion opened 8 months ago

TomElliottFlexion commented 8 months ago

Acceptance Criteria

Pain Avoided/Frustration Saved

Breadth/Pervasiveness of Problem

Complexity of Problem (Low, Medium, High) and Why it's Complex

Notes

Mwindo commented 3 months ago

Wow, this was bizarre. The issue has nothing to do with any of the things listed above.

After some trial and error, I discovered the root of the problem is that there are new SVG icons bundled with USWDS that are interfering with how Cypress injects styles into the DOM snapshots. Here is an example of such an SVG icon:

Screenshot 2024-08-05 at 6.04.08 PM.png

The <style></style> section in particular is causing problems for Cypress. Here is the garbled CSS that we get within Cypress snapshots due to this "bad" SVG:

Screenshot 2024-08-05 at 5.47.23 PM.png

When I clean these SVGs up using svgo, the Cypress snapshot issues are resolved.

One way to fix this issue, then, is to use svgo, which is already a dependency of uswds, and clean up the images upon npm i. I.e., put this in package.json:

"postinstall": "husky install && cd ./node_modules/@uswds/uswds/dist/img && npx svgo -r ."

where the && portion is new. I've verified this works locally. I am not yet sure this is the best solution.

Mwindo commented 3 months ago

I opened an issue with USDWS ("Clean up your SVGs, please!") and will ask the team if they have a better solution than the one I posted above.

Mwindo commented 3 months ago

A quick finding:

While everything I said above still holds, I have been investigating what is happening on our end (e.g., when we bundle) that might be contributing to the issue (i.e., trying to answer the question "why are there not more reports of this error from other teams?").

Somehow, it seems the issue with Cypress styles and these SVGs has to do with the fact that they are loaded inline via our esbuild:

    loader: {
      '.html': 'text',
      '.pdf': 'file',
      '.png': 'dataurl',
      '.svg': 'dataurl',
      '.ttf': 'file',
      '.woff': 'file',
      '.woff2': 'file',
    },

If I switch from '.svg': 'dataurl' to '.svg': 'file' (and also set publicPath: '/' because otherwise Cypress cannot locate the image in the DOM via the relative import), everything works.

Mwindo commented 2 months ago

Still waiting on USWDS, but there has been an update.

Mwindo commented 3 weeks ago

Finally, an update!: https://github.com/uswds/uswds/issues/6011. Looks like we should be able to update when they next release.

Mwindo commented 1 week ago

This should be good to go!

Image

Hopefully we can update dependencies to use the new version. I'll message the dev(s) on dependency rotation this week.