Are params reset after a frame rendering?

Using Hotwire & simple_calendar gem on a project and I’m facing an interesting issue.

The app is a dead-simple calendar on which we can add events.
Each calendar’s cell has a “+” sign, which displays a modal containing events/_form. On POST, the whole calendar_frame is replaced so the newly created event is displayed. Works like a charm, even if it may not be optimized.

Thing is, simple_calendar gem uses theses helpers to create “Previous” and “Next” (months, weeks, …) links:

view_context.url_for(
  @params.merge(start_date_param => (date_range.first - 1.day).iso8601)
)

causing “Previous” and “Next” hrefs to includes the previously POSTed params:

http://localhost:3000/events?event%5Bcalendar_id%5D=171&event%5Bdescription%5D=&event%5Bend_date%5D=&event%5Bis_related_to_a_user%5D=0&event%5Blocation%5D=&event%5Borganization_id%5D=&event%5Bstart_date%5D=2022-02-02T00%3A00%3A00%2B00%3A00&event%5Btitle%5D=An+event&start_date=2022-03-07

instead of

http://localhost:3000/?start_date=2022-03-07

which point to /events !

Question is, should I manually reset the parameters on a turbo_frame rendering ? I believe I should, but how ?

I’ve tried params = nil and request.parameters.delete('event'), but params keeps being merged.

Thanks for this amazing lib btw !

Things always look better in the morning (and after reading the doc and understanding it a bit better).

I believe I’m overusing <turbo-stream action="replace"> tags and didn’t consider this part of the doc:

The replace visit action uses history.replaceState to discard the topmost history entry and replace it with the new location.

On my way to re-read the docs, find another approach and post update here

1 Like