Optimizing responses on tables · Issue #91 · unpoly/unpoly · GitHub
Skip to content

Optimizing responses on tables #91

Closed

Description

@thinkwelltwd

In the Server Protocol docs, under Optimizing responses, it says that:

Server-side code is free to optimize its response by only returning HTML that matches the selector. For example, you might prefer to not render an expensive sidebar if the sidebar is not targeted.

I have large tables where I need to swap out table rows; each tr tag has an ID. The server response includes only the tr tag, so the entire response contents match the ID selector. However, unpoly can't find the ID in the response and updates the body instead of the table row.

If the server returns the entire table, then unpoly correctly updates the table. I also tried having the server return the tbody tag of the table, but unpoly couldn't extract the table row.

Then also tried assigning the ID to the tbody tag, and same result as tr - the content loads in the body tag.

The only way that I've encountered to get a tbody or tr tag swapped is to send the entire table from the server. That's still more efficient than the entire page, but it seems like a bug to me.

Activity

  1. adam12 commented on Aug 6, 2019

    @adam12
    Member

    Have you tried rendering a minimal table with only that tr? Then using the id selector as you were.

    I can't find a source to back this up right now, but I feel like there are certain tags that just can't exist on their own, and browser react indeterminately when they see them. My guess is tr, td, and a few others (tbody?) will just parse oddly without a parent table.

  2. triskweline commented on Aug 6, 2019

    @triskweline
    Contributor

    Like @adam12 said, wrap your <tr> in a <table> and it will work.

    Unpoly uses your browser to parse the server response. The response always needs to be a valid HTML fragment, or the browser will consider it tag soup and silently rewrite your HTML:

    dom_parser

  3. thinkwelltwd commented on Aug 6, 2019

    @thinkwelltwd
    Author

    Have you tried rendering a minimal table with only that tr? Then using the id selector as you were.

    Yes, that's what I meant by "If the server returns the entire table, then unpoly correctly updates the table."

    Unpoly uses your browser to parse the server response. The response always needs to be a valid HTML fragment.

    Ok, thanks for the explanation. I don't know if there'd be a way to clarify the Optimizing responses section or not; something like:

    Server-side code is free to optimize its response by only returning HTML that matches the selector. (The entire response body must be valid HTML as it is parsed by the browser. Tags that cannot exist on their own, such as tr should be wrapped in a table tag.)

    I'm switching from IntercoolerJS where the response consisting only of tr tag worked fine. I was using ic-replace-target, which inserts the entire response - apparently with no browser parsing of the HTML.

    Sorry for the bother on this ticket. Now that I understand the difference, it'll not be a problem to work with it.

  4. triskweline commented on Sep 22, 2025

    @triskweline
    Contributor

    Unpoly 3.12.0-rc6 can process table rows without an enclosing <table>.

  5. alexandremjacques commented on Sep 22, 2025

    @alexandremjacques

    Unpoly 3.12.0-rc6 can process table rows without an enclosing <table>.

    Oh. That's interesting. Any preview documentation on how to do that?

  6. triskweline commented on Sep 22, 2025

    @triskweline
    Contributor

    Any preview documentation on how to do that?

    There's no new API. You target any <tr> element and the server can now respond with HTML that only contains an updated <tr> element.

  7. thinkwelltwd commented on Sep 24, 2025

    @thinkwelltwd
    Author

    Many thanks, @triskweline! What a nice enhancement. 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions