Skip to content

fix: readSignals reads GET signals from query parameter instead of header (#4020)#4026

Merged
987Nabil merged 1 commit intozio:mainfrom
987Nabil:fix/datastar-readSignals-query-param
Mar 14, 2026
Merged

fix: readSignals reads GET signals from query parameter instead of header (#4020)#4026
987Nabil merged 1 commit intozio:mainfrom
987Nabil:fix/datastar-readSignals-query-param

Conversation

@987Nabil
Copy link
Copy Markdown
Contributor

Summary

The Datastar JS SDK sends signals as a datastar query parameter for GET requests, not as a header. This fix updates the Scala SDK to correctly read signals from the query parameter for GET requests, addressing the inconsistency.

Changes

  • Updated readSignals to use request.queryParam("datastar") for GET requests instead of request.header[String]("datastar")
  • Updated all 6 GET tests to use query parameters instead of headers
  • Updated test names to reflect the correct parameter type

Fixes #4020

Copilot AI review requested due to automatic review settings March 13, 2026 15:22
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 13, 2026

Deploy Preview for zio-http ready!

Name Link
🔨 Latest commit a4a8c55
🔍 Latest deploy log https://app.netlify.com/projects/zio-http/deploys/69b433379741270007aca8f2
😎 Deploy Preview https://deploy-preview-4026--zio-http.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Aligns the Scala Datastar SDK with the Datastar JS client behavior by reading GET request signals from the datastar query parameter (instead of a request header), and updates the associated test suite accordingly.

Changes:

  • Updated readSignals GET handling to read datastar from request.queryParam("datastar").
  • Updated GET-path tests to pass datastar via query parameters and renamed tests to reflect this.
  • Kept non-GET behavior reading signals from the request body.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
zio-http-datastar-sdk/src/main/scala/zio/http/datastar/DatastarPackageBase.scala Switches GET signal extraction from header to query param.
zio-http-datastar-sdk/src/test/scala/zio/http/datastar/ReadSignalsSpec.scala Migrates GET tests to query-param based requests and updates test names.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +29 to +32
test("should read signals from datastar query parameter with simple data") {
val jsonData = """{\"{count\"":42}"""
val request = Request
.get(URL.root / "test")
.addHeader(Header.Custom("datastar", jsonData))
.get((URL.root / "test").addQueryParams(QueryParams("datastar" -> jsonData)))
Comment on lines +40 to +43
test("should read signals from datastar query parameter with complex data") {
val jsonData = """{"{name":"John Doe","age":30,"email":"john@example.com"}"""
val request = Request
.get(URL.root / "test")
.addHeader(Header.Custom("datastar", jsonData))
.get((URL.root / "test").addQueryParams(QueryParams("datastar" -> jsonData)))
Comment on lines +53 to +56
test("should read signals from datastar query parameter with nested data") {
val jsonData = """{"{user":{"name":"Jane","age":25,"email":"jane@test.com"},"active":true}"""
val request = Request
.get(URL.root / "test")
.addHeader(Header.Custom("datastar", jsonData))
.get((URL.root / "test").addQueryParams(QueryParams("datastar" -> jsonData)))
},
test("should fail when JSON doesn't match schema") {
val jsonData = """{"wrong":"field"}"""
val jsonData = """{"{wrong":"field"}"""
@987Nabil 987Nabil force-pushed the fix/datastar-readSignals-query-param branch from 73c788c to 299ece9 Compare March 13, 2026 15:51
@987Nabil 987Nabil force-pushed the fix/datastar-readSignals-query-param branch from 299ece9 to a4a8c55 Compare March 13, 2026 15:54
@987Nabil 987Nabil merged commit c4edaa7 into zio:main Mar 14, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(datastar): readSignals reads GET signals from header instead of query parameter

2 participants