bigskysoftware / bigskysoftware/htmx

hx-vals + json-enc: first-level empty array is dropped

Open
#3,845 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
49.4k
Forks
1.7k
Avg merge
3d 22h
Merged PRs (30d)
30

Description

htmx.org 2.0.10, json-enc 2.0.3.

In my case this bug breaks some cases of the programmatic population of `hx-vals`. E.g. as in the example from the [docs](https://htmx.org/attributes/hx-vals/): `hx-vals='js:{...foo()}'` where `foo()` returns a map where some first-level value is `[]`.

## Steps

See https://jsfiddle.net/r4sgw3nh:

```html

Click me

```

1) Click `Click me`.
2) Inspect the made request payload in the browser devtools.

# Actual

`{"secondLevel":{"values":[]}}`

# Expected

`{"firstLevel":[],"secondLevel":{"values":[]}}`

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided JSFiddle with htmx 2.0.10 and json-enc 2.0.3, then inspect the request payload in browser devtools. Trace how hx-vals is encoded, focusing on why a first-level empty array is omitted while nested arrays are preserved. Done means the payload includes both firstLevel:[] and secondLevel.values:[] as shown in Expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.