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

fix(EnterpriseAlert): render span when inline #881

Merged
merged 1 commit into from
Feb 15, 2023

Conversation

BRKalow
Copy link
Contributor

@BRKalow BRKalow commented Feb 15, 2023

🎟️ Asana Task
πŸ” Preview Link


Description

When used inline, EnterpriseAlert currently renders a div as its root element. This is problematic when used in MDX specifically, as it will most likely be a child of a p. Per the spec, p elements cannot contain block-level elements and so the HTML is invalid. This results in React hydration errors.

I've updated EnterpriseAlert to render span as its root element if the inline prop is passed to fix this.

PR Checklist πŸš€

Items in this checklist may not may not apply to your PR, but please consider each item carefully.

  • Add Asana and Preview links above.
  • Conduct thorough self-review.
  • Add or update tests as appropriate.
  • Conduct reasonable cross browser testing for both compatibility and responsive behavior (We have a Sauce Labs account for this, if you don't have access, just ask!).
  • Conduct reasonable accessibility review (use the WAS as a guide or an axe browser plugin until we establish more formal checks).
  • Identify (in the description above) and document (add Asana tasks on this board) any technical debt that you're aware of, but are not addressing as part of this PR.

@BRKalow BRKalow requested a review from a team February 15, 2023 17:09
@changeset-bot
Copy link

changeset-bot bot commented Feb 15, 2023

πŸ¦‹ Changeset detected

Latest commit: 2e941fd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hashicorp/react-enterprise-alert Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Feb 15, 2023

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Updated
react-components βœ… Ready (Inspect) Visit Preview Feb 15, 2023 at 5:09PM (UTC)

Comment on lines +27 to +28
// This ensures we aren't producing invalid HTML when rendering inline alerts within MDX. When used inline, we might end up nesting a div inside of a p. This is invalid as p cannot contain block-level elements (ref: https://www.w3.org/TR/html401/struct/text.html#h-9.3.1).
const Element = inline ? 'span' : 'div'
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL πŸ’―

@BRKalow BRKalow merged commit 406fa0c into main Feb 15, 2023
@BRKalow BRKalow deleted the brk.fix/enterprise-alert-inline branch February 15, 2023 17:55
@hashibot-web hashibot-web mentioned this pull request Feb 15, 2023
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.

None yet

2 participants