Skip to content

Add JSONPath search to CodeBlock - #78

Open
hannesstruss wants to merge 6 commits into
livewire-kt:mainfrom
hannesstruss:codex/jsonblock-jsonpath
Open

hannesstruss wants to merge 6 commits into
livewire-kt:mainfrom
hannesstruss:codex/jsonblock-jsonpath

Conversation

@hannesstruss

@hannesstruss hannesstruss commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Searchable JSON CodeBlocks evaluate queries beginning with $ as JSONPath and show an array of matching values. Type \$ to search for a literal dollar sign. Ordinary queries keep text highlighting, next/previous navigation, and scroll position when the payload changes.

JSONPath waits for typing to pause and keeps the previous result visible while editing the query for the same payload. Small results open expanded, and large results start collapsed below the root. The compact field defaults to the top, with an option to put it underneath and a help button linking to Livewire’s reference.

Compatibility

  • Protocol version 3 requires updating the desktop host and client library together. The new layout JSON decoder ignores unknown fields.
  • Kotlin consumers should recompile against the new CodeBlock signature. The Android JSONPath4K artifact requires API 30 for apps embedding the Android host-ui renderer. The Android client does not depend on JSONPath4K.
  • JSONPath4K keeps its transitive Napier dependency. Excluding it broke desktop ProGuard and Android R8 because JSONPath4K’s default listener still references Napier even when a custom compiler is supplied.

Validation

  • 19 focused JVM tests passed, covering discovery packets, layout serialization, JSONPath evaluation, scroll preservation, literal-dollar search, and renderer behavior. The desktop host compiled successfully.
  • Desktop release shrinking passed with Napier restored. A focused Android R8 smoke check also passed with Napier.

@hannesstruss
hannesstruss marked this pull request as ready for review November 18, 2026 13:30
@r0adkll
r0adkll requested review from EricKuck and r0adkll November 18, 2026 13:41
@r0adkll r0adkll added the enhancement New feature or request label Nov 18, 2026

@r0adkll r0adkll left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Review notes on the JSONPath search. Two things to fix before merge are in the comments on CodeBlockNodeContent.kt:130 (scroll position resets) and CodeBlock.kt:64 (protocol version). The other comments are performance and polish notes. They're mostly about large payloads and can be follow-ups.

One more that isn't in the diff: docs/reference/ui.md (CodeBlock row around line 48) still lists only content, language, searchable and initialTreeState. It should document searchPlacement and the $-prefixed JSONPath behaviour.

JSONPath4K retains references to its default Napier listener even when a custom compiler is supplied. Desktop ProGuard and Android R8 both fail to resolve those references when Napier is excluded.

@r0adkll r0adkll left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Thanks for the update. It addresses all of the earlier feedback, so I've resolved those threads. One new issue is left, in the comment below.

// one job per CodeBlock run at a time so rapid payload changes cannot pile up work.
val pathDispatcher = remember { Dispatchers.Default.limitedParallelism(1) }
var document by remember(json) { mutableStateOf<JsonElement?>(null) }
var pathResult by remember(json, isJsonPath) { mutableStateOf<String?>(null) }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Content updates flash the full document while a JSONPath query is active. pathResult is still remembered under json, and the collector below restarts on LaunchedEffect(json, isJsonPath). So when the guest sends a new content patch while a $ query is showing:

  1. pathResult resets to null, displayedPath becomes null, and key(displayedPath != null) switches to the full, unfiltered document.
  2. The restarted snapshotFlow { query }.debounce(...) waits the full 200 ms before its first emission, even though the query hasn't changed. Then it parses and evaluates.
  3. The key switches back and JsonTree is rebuilt with the result.

With live data such as the network inspector, the view keeps flipping between the whole document and the filtered result. Before this change it flipped to a spinner, which was less jarring.

Suggestion: remember pathResult (and invalidPath) by isJsonPath only, so the last result stays on screen until the new one replaces it. Also skip the debounce for the first evaluation after json changes, e.g. evaluate the current query right away when the effect starts, then drop(1) and debounce later edits. A test like ordinaryTreeKeepsItsScrollPositionAcrossPayloadUpdates, but with a $ query active, would cover it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Automated reply: Fixed in a7e01cf. The typing debounce runs separately from payload updates, so new payloads reuse the settled query. The last filtered tree stays visible until its replacement is ready. A loader appears before the first result.

The regression test checks that the result advances during rapid updates and the unfiltered document stays hidden. Here’s the Playground demo with $.tick active:

Animated demo of JSONPath results advancing while the JSON payload updates

This branch has not been deployed

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants