fix: inject BUILD_TAG into sw.js via regex so a fallback bump cannot freeze the SW version
This commit is contained in:
@@ -392,11 +392,18 @@ app.get('/sw.js', (c) => {
|
|||||||
return c.text('Service worker not found', 404);
|
return c.text('Service worker not found', 404);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Inject the build tag: replace the placeholder with the real value.
|
// Inject the build tag: replace the whole fallback expression with the
|
||||||
|
// real value. Matched by REGEX, not an exact string — an exact match broke
|
||||||
|
// the moment the fallback literal in sw.js was bumped ('v1.0.3' → 'v1.0.4'),
|
||||||
|
// after which the replacement silently did nothing, the SW version froze,
|
||||||
|
// and clients never saw another update no matter how many times we deployed.
|
||||||
const src = _swSource.replace(
|
const src = _swSource.replace(
|
||||||
"typeof __BUILD_TAG__ !== 'undefined' ? __BUILD_TAG__ : 'v1.0.3'",
|
/typeof __BUILD_TAG__ !== 'undefined' \? __BUILD_TAG__ : '[^']*'/,
|
||||||
JSON.stringify(BUILD_TAG)
|
JSON.stringify(BUILD_TAG)
|
||||||
);
|
);
|
||||||
|
if (src === _swSource) {
|
||||||
|
console.error('[sw] BUILD_TAG injection failed — placeholder not found in sw.js');
|
||||||
|
}
|
||||||
return c.text(src, 200, {
|
return c.text(src, 200, {
|
||||||
'Content-Type': 'application/javascript; charset=utf-8',
|
'Content-Type': 'application/javascript; charset=utf-8',
|
||||||
'Cache-Control': 'no-store, no-cache, must-revalidate',
|
'Cache-Control': 'no-store, no-cache, must-revalidate',
|
||||||
|
|||||||
Reference in New Issue
Block a user