fasthtml icon indicating copy to clipboard operation
fasthtml copied to clipboard

[BUG] Out of band swap with tables is getting confused

Open kevinpauli opened this issue 9 months ago • 1 comments

Important Notice We do not provide support through GitHub issues. For community-based help, please use either:

If you're reporting a bug, please continue with this template.

Describe the bug Out of band swap with tables is getting confused. Divs work fine.

Minimal Reproducible Example Provide a minimal code snippet that reproduces the issue. This is crucial for us to understand and fix the bug quickly.

from datetime import datetime

from fasthtml.common import *

app, rt = fast_app(live=True)


##############################################


def p_1():
    return P(f"Div 1 {datetime.now()}", A("swap me", hx_get="/swap-divs", hx_swap="outerHTML", hx_target="closest p"))


def div_1():
    return Div(p_1())


def div_2():
    return Div(P(f"Div 2 {datetime.now()}"), id="div-2", hx_swap_oob="true")


@rt("/swap-divs")
def get():
    return p_1(), div_2()


##############################################


def table_1_row():
    return Tr(
        Td(f"{datetime.now()}"),
        Td(A("swap me", hx_get="/swap-tables", hx_swap="outerHTML", hx_target="closest tr")),
    )


def table_1():
    return Table(
        Thead(Th("Time 1"), Th("")),
        Tbody(table_1_row()),
    )


def table_2():
    return Table(
        Thead(Th("Time 2"), Th("")), Tbody(Tr(Td(f"{datetime.now()}"), Td(""))), id="table-2", hx_swap_oob="true"
    )


@rt("/swap-tables")
def get():
    return table_1_row(), table_2()


##############################################


@rt("/")
async def get():
    return Div(
        Titled(
            "This works; swaps both",
            div_1(),
            div_2(),
        ),
        Titled(
            "This gets confused; inserts table 2 into table 1",
            table_1(),
            table_2(),
        ),
    )


serve()

Expected behavior Expected the times in table 1 and table 2 to get updated when achor is clicked, similar to how the divs behave.

Environment Information Please provide the following version information:

  • fastlite version: 0.1.2
  • fastcore version: 1.7.29
  • fasthtml version: 0.12.4

Confirmation Please confirm the following:

  • [x] I have read the FAQ (https://docs.fastht.ml/explains/faq.html)
  • [x] I have provided a minimal reproducible example
  • [x] I have included the versions of fastlite, fastcore, and fasthtml
  • [x] I understand that this is a volunteer open source project with no commercial support.

Additional context Add any other context about the problem here.

Screenshots If applicable, add screenshots to help explain your problem.

kevinpauli avatar Mar 04 '25 22:03 kevinpauli