Skip to content

support json parsing to hx-live data proxy#3822

Open
MichaelWest22 wants to merge 1 commit into
bigskysoftware:four-devfrom
MichaelWest22:hx-live-data
Open

support json parsing to hx-live data proxy#3822
MichaelWest22 wants to merge 1 commit into
bigskysoftware:four-devfrom
MichaelWest22:hx-live-data

Conversation

@MichaelWest22
Copy link
Copy Markdown
Collaborator

Description

in hx-live we have a new data proxy and we have found that if we use JSON parse and stringify we can store and retrive data and retain the JSON supported data types like boolean, numeric and arrays. This works well for all data I have tested for except strings of numbers with leading zero which will be converted to a number. But this seems and unlikely edge case and you can work around this by accessing the this.dataset.xxxx directly.

I've also extended q() to have data as a proxy of the data for the first returned element.

Also found parseConfig can use the JSON.parse trick here as well to replace the true, false and numeric handling with a simple json parse. From my testing this works well for all the situations I could find. JSON.parse auto converts true, false and number strings to their real type.

Finally I also extended morphIgnore to handle prefixes with startsWith() as well so that it is possible to easily use this to protect client side data-* attributes if needed.

Corresponding issue:

Testing

added some hx-live tests for the data proxy.

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

@MichaelWest22 MichaelWest22 added the htmx 4 Issues specific to htmx version 4 label Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

htmx 4 Issues specific to htmx version 4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant