Skip to content

Commit

Permalink
conscript/local: temporary fix for form bug
Browse files Browse the repository at this point in the history
This fix is temporary, because it seems wrong to use as the request the
request of the original study. So far, this didn't cause any errors, but
I feel that this is not the right approach.

Bug in previous version: in `preview`, if a form got submitted on page 1
and on page 2 we have another form, then somehow the request persisted
in such a way that the form on page 2 was processed with the values from
the previous form. If both forms required a number, then the first form
would be submitted successfully, and then second form would two,
literally skipping the page!
  • Loading branch information
MarcKaufmann committed May 21, 2024
1 parent 1bcb9f7 commit c2ff054
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions conscript/local.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,27 @@
(sync never-evt))
(stop))

(define (run-study a-study)
(define (run-study a-study [req (current-request)])
(eprintf "Running study: ~a~n" a-study)
(define paramz (current-parameterization))
(parameterize ([current-vars (or (current-vars) (make-hash))]
[current-data (make-hash)])
(let loop ([this-step (car (study-steps a-study))])
(eprintf "Loop: this-step is ~a~n" this-step)
(if (not this-step)
`(continue ,paramz)
(match (run-step this-step)
(match (run-step this-step req)
[(? response? res)
(send/back res)]

[`(to-step ,to-step-id ,paramz)
(define next-step
(find-step a-study to-step-id))
(call-with-parameterization paramz
(lambda ()
(loop next-step)))]
[`(continue ,paramz)
(redirect/get/forget/protect)
(match ((step-transition this-step))
[(? done?)
`(continue ,paramz)]
Expand All @@ -118,28 +130,26 @@
(call-with-parameterization paramz
(lambda ()
(loop next-step)))])]
[`(to-step ,to-step-id ,paramz)
(define next-step
(find-step a-study to-step-id))
(call-with-parameterization paramz
(lambda ()
(loop next-step)))]
[(? response? res)
(send/back res)])))))
)))))

(define (run-step a-step)
(define (run-step a-step [req (current-request)])
(eprintf "run-step: running step ~a~n" a-step)
(define paramz #f)
(call-with-current-continuation
(lambda (return)
(send/suspend/dispatch/protect
(lambda (embed/url)
(parameterize ([current-embed/url (lambda (hdl)
(embed/url (λ (req)
(call-with-parameterization paramz
(lambda ()
(parameterize ([current-request req])
(hdl req)))))))]
[current-return return])
(parameterize ([current-embed/url
(lambda (hdl)
(embed/url
(λ (req)
(call-with-parameterization
paramz
(lambda ()
(parameterize ([current-request req])
(hdl req)))))))]
[current-return return]
[current-request req])
(set! paramz (current-parameterization))
(if (step/study? a-step)
(return (run-study (step/study-study a-step)))
Expand Down

0 comments on commit c2ff054

Please sign in to comment.