Skip to content

Conversation

macobo
Copy link
Contributor

@macobo macobo commented Apr 29, 2025

Idea from the lovely @apata for making easier breaking changes in the dashboard API: reload the dashboard when the internal API version changes.

This will help us make 'breaking' changes easier.

@macobo macobo force-pushed the dashboard-reload branch 2 times, most recently from 06e5394 to d5a1f09 Compare April 29, 2025 10:19
Idea from the lovely @apata for making easier breaking changes in the
dashboard API: reload the dashboard when the internal API version
changes.
@macobo macobo force-pushed the dashboard-reload branch from d5a1f09 to 6d96a70 Compare April 29, 2025 10:21
@macobo macobo requested a review from apata April 29, 2025 10:50
payload,
EXPECTED_API_VERSION
})
window.location.reload()
Copy link
Contributor

Choose a reason for hiding this comment

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

In my mind, this risks us creating an endless reload loop for all dashboards when we fail to keep things in sync. There's a small chance of that happening, but the damage would be great.

I think we could mitigate it by instead doing window.location.replace, adding the r=... query parameter with value of EXPECTED_API_VERSION, like r=5.

Then, in this function, we can make the reload conditional on query not containing r=${EXPECTED_API_VERSION}.

There's a decent example of something similar in url-search-params.ts: perhaps this logic could be colocated there?

@@ -115,7 +121,8 @@ defmodule PlausibleWeb.Api.StatsController do
comparison_plot: comparison_result && plot_timeseries(comparison_result, metric),
comparison_labels: comparison_result && label_timeseries(comparison_result, nil),
present_index: present_index,
full_intervals: full_intervals
full_intervals: full_intervals,
api_version: @api_version
Copy link
Contributor

Choose a reason for hiding this comment

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

Having it in the JSON payload is good: it catches the eye when refactoring the payloads server side. But, it also misses a few routes that the dashboard is using, like sites, segments, funnels.

Did you consider providing it in a header?

It seems to me that if it were a header, we could provide it with a router plug on all those APIs and use it as the definitive trigger for reloading incompatible dashboards.

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.

3 participants