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

USWDS-Sandbox - Test: Banner Elements #170

Draft
wants to merge 6 commits into
base: vite-sandbox
Choose a base branch
from

Conversation

mejiaj
Copy link
Contributor

@mejiaj mejiaj commented Dec 27, 2024

Created to reproduce issue outlined in uswds/web-components#65 (comment).

Preview

Preview link →

Problem statement

The following error is happening on Vite powered environments (i.e. AstroJS):

@uswds_web-components_components_usa-banner.js?v=abb78aad:1246 Uncaught (in promise) TypeError: currentDirective._$initialize is not a function
    at resolveDirective (@uswds_web-components_components_usa-banner.js?v=abb78aad:1246:24)
    at AttributePart._$setValue (@uswds_web-components_components_usa-banner.js?v=abb78aad:1668:14)
    at TemplateInstance._update (@uswds_web-components_components_usa-banner.js?v=abb78aad:1318:16)
    at _ChildPart._commitTemplateResult (@uswds_web-components_components_usa-banner.js?v=abb78aad:1524:16)
    at _ChildPart._$setValue (@uswds_web-components_components_usa-banner.js?v=abb78aad:1410:12)
    at render (@uswds_web-components_components_usa-banner.js?v=abb78aad:1840:8)
    at R.update (@uswds_web-components_components_usa-banner.js?v=abb78aad:1901:24)
    at R.performUpdate (@uswds_web-components_components_usa-banner.js?v=abb78aad:732:14)
    at R.scheduleUpdate (@uswds_web-components_components_usa-banner.js?v=abb78aad:676:25)
    at R.__enqueueUpdate (@uswds_web-components_components_usa-banner.js?v=abb78aad:652:25)

This issue is coming from a combination of issues lit directives [i.e. classMap and unsafeHTML] and vite development environment.

How we're using directives

We're using the following lit directives:

classMap

We're using classMap to toggle usa-banner__header--expanded, which is used mostly in mobile to toggle between the Here's how you know text and the close button icon.

capture -Arc-2024-12-30

unsafeHTML

This is used to pass strong text in the HTTPS section. Without it we (and users) would get this when adding their own text i.e. translations.

image

Workarounds

  1. Force vite to use production build, like in 4521695.
  2. Use CDN version of component
    <script
      type="module"
      src="https://esm.sh/@uswds/[email protected]/components/usa-banner">
    </script>
  3. Avoid using directives (requires spike), biggest issue would be finding alternatives for the HTTPS text being escaped. Example without using unsafeHTML:

"federalist": "npm run build",
"dev": "vite",
"build": "vite build",
"start": "NODE_ENV=production npm run dev",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tip

This NODE_ENV forces vite to run in production mode and should resolve the initializer conflict.

- Use modules in `package.json`
- Set baseURL for cloud.gov pages
- Remove lit as a dependency
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.

1 participant