Skip to content

Duplicate request passed to Dispatcher#17

Merged
ismasan merged 1 commit intomainfrom
dup_datastar_request
Apr 22, 2026
Merged

Duplicate request passed to Dispatcher#17
ismasan merged 1 commit intomainfrom
dup_datastar_request

Conversation

@ismasan
Copy link
Copy Markdown
Collaborator

@ismasan ismasan commented Apr 22, 2026

So that we have a snapshot of the request in case Rack middleware mutates the original request

The problem

Rack middleware such as Rack::URLMap (used for mounting Rack apps under a path prefix) adds the prefix to Request#env['SCRIPT_NAME'], and then clear it out once the mounted app as served a response.

map '/sourced' do
  run MyMountedApp
end

However, Datastar's async fibers run after the host app has returned a response, by which time the middleware has reset the script name from '/sourced' back to ''. Any code (such as template rendering) that assumes the expected path prefix (ex for URL building) will break.

The solution

When initialising the Datastar Dispatcher, make sure to make a copy of the request, so that middleware mutating the original request doesn't mutate the one held by SSE fibers.

So that we have a snapshot of the request in case Rack middleware mutates the original request
@ismasan ismasan merged commit 8ad9d57 into main Apr 22, 2026
1 check 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.

1 participant