Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix icons with same name not changing when config changes #722

Merged
merged 4 commits into from
Sep 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/frontend/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ export function Api({
}) {
let status: ServerStatus = STATUS.IDLE;
let timeoutId: TimeoutID;
// We append this to requests for presets and map styles, in order to override
// the local static server cache whenever the app is restarted. NB. sprite,
// font, and map tile requests might still be cached, only changes in the map
// style will be cache-busted.
const startupTime = Date.now();
// We append this to requests for presets, icons and map styles, in order to
// override the local static server cache whenever the app is restarted. NB.
// sprite, font, and map tile requests might still be cached, only changes in
// the map style will be cache-busted.
let startupTime = Date.now();

const req = ky.extend({
prefixUrl: baseUrl,
Expand Down Expand Up @@ -456,8 +456,12 @@ export function Api({

function done(err) {
clearTimeout(timeoutId);
if (err) reject(err);
else resolve();
if (err) return reject(err);
// startupTime is use for cache-busting. When we replace the
// config we want the cache to be reset so that icons with the
// same name are not cached
startupTime = Date.now();
resolve();
}
})
);
Expand Down Expand Up @@ -563,7 +567,7 @@ export function Api({
// Some devices are @4x or above, but we only generate icons up to @3x
// Also we don't have @1.5x, so we round it up
const roundedRatio = Math.min(Math.ceil(pixelRatio), 3);
return `${BASE_URL}presets/default/icons/${iconId}-medium@${roundedRatio}x.png`;
return `${BASE_URL}presets/default/icons/${iconId}-medium@${roundedRatio}x.png?${startupTime}`;
},

// Return the url for a media attachment
Expand Down