Skip to content

bug: (HTMX compatibility) ion-button fails to hydrate when doing DOM replacement via htmx #30744

@Gleek

Description

@Gleek

Prerequisites

Ionic Framework Version

v8.x

Current Behavior

After an htmx swap/boost that inserts new DOM containing an ion-button, the Ionic web component fails to hydrate and no button is rendered (appears missing).

Expected Behavior

After an htmx swap/boost that inserts new DOM containing an ion-button, the Ionic web component should hydrate properly, displaying the button as expected, with all active functionality.

Steps to Reproduce

pre-requisites

  1. Save the HTML file: Save the provided HTML as ionic-button.html
<!DOCTYPE html>
<html>
<head>
  <title>ionic button</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core/css/ionic.bundle.css">
  <script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.esm.js"></script>
  <script nomodule src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.7/dist/htmx.min.js"></script>
</head>
<body>
  <h1>ionic button</h1>
  <ion-button fill="outline" id="collabToggle">My button</ion-button>
  <div hx-boost="true">
    <a href="/ionic-button.html">HTMX load</a>
  </div>
</body>
</html>
  1. Run a Local Server:
    Eg: python3 -m http.server 6000
  2. Visit http://localhost:8000/ionic-button.html.

reproduction:

  1. Load Initial Page: Ensure ion-button is correctly rendered with styling.

  2. HTMX Boost Action:

    • Click the “HTMX load” link in the document.
  3. Post-Swap Observation:

    • Note whether ion-button appears and functions after the page content is replaced by hx-boost.

Expected vs. Actual Outcome

  • Expected: The ion-button should maintain its rendering and functionality.
  • Actual: After hx-boost replaces the content, ion-button may not hydrate, rendering it non-functional or missing styling.

The code is simply using hx-boost to replace the body with the same content again. All of the html elements are rendered including other ionic components, if any, except the buttons which don't hydrate for some reason.

Code Reproduction URL

NA - Steps to reproduce include the application

Ionic Info

NA
I'm using the CDN link directly and using webcomponents with vanilla js

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions