Skip to content

Commit aa1820a

Browse files
committed
v3.66.399
1 parent 716309d commit aa1820a

3 files changed

Lines changed: 5 additions & 68 deletions

File tree

build.mjs

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,6 @@ async function emit(rel, code) {
4141
await fs.writeFile(dest, code);
4242
}
4343

44-
const swRegisterSource = `if ('serviceWorker' in navigator) {
45-
window.addEventListener('load', function () {
46-
navigator.serviceWorker.register('/sw.js').catch(function (e) {
47-
console.error('Service worker registration failed', e);
48-
});
49-
});
50-
}
51-
`;
52-
5344
async function run() {
5445
await fs.rm(dist, { recursive: true, force: true });
5546
await fs.mkdir(dist, { recursive: true });
@@ -79,11 +70,6 @@ async function run() {
7970
assetMap.set(rel, hashed);
8071
}
8172

82-
// Service worker registration shim (external, to satisfy strict CSP).
83-
const swReg = (await transform(swRegisterSource, { loader: 'js', minify: true })).code;
84-
const swRegRel = hashedName('js/sw-register.js', swReg);
85-
await emit(swRegRel, swReg);
86-
8773
// Replace original asset paths with hashed ones in HTML. Longest keys first
8874
// so shorter paths can't partially shadow longer ones.
8975
const replacements = [...assetMap.entries()].sort((a, b) => b[0].length - a[0].length);
@@ -92,8 +78,7 @@ async function run() {
9278
return html;
9379
};
9480

95-
let indexHtml = rewriteHtml(await fs.readFile(path.join(root, 'index.html'), 'utf8'));
96-
indexHtml = indexHtml.replace('</body>', ` <script src="${swRegRel}"></script>\n</body>`);
81+
const indexHtml = rewriteHtml(await fs.readFile(path.join(root, 'index.html'), 'utf8'));
9782
await emit('index.html', await minifyHtml(indexHtml, htmlMinifyOptions));
9883

9984
for (const file of await walk(path.join(root, 'static'))) {
@@ -102,73 +87,25 @@ async function run() {
10287
else await emit(rel, await fs.readFile(file));
10388
}
10489

105-
// Precache the full app shell: index, hashed assets, static pages.
106-
const precache = ['/'];
107-
for (const hashed of assetMap.values()) precache.push('/' + hashed);
108-
precache.push('/' + swRegRel);
109-
for (const file of await walk(path.join(dist, 'static'))) {
110-
if (file.endsWith('.html')) precache.push('/' + toPosix(path.relative(dist, file)));
111-
}
112-
113-
const version = sha8(Buffer.from([...assetMap.values()].sort().join('|')));
114-
const sw = `const CACHE = 'nym-${version}';
115-
const PRECACHE = ${JSON.stringify(precache)};
116-
self.addEventListener('install', (e) => {
117-
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(PRECACHE)).then(() => self.skipWaiting()));
118-
});
119-
self.addEventListener('activate', (e) => {
120-
e.waitUntil(caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))).then(() => self.clients.claim()));
121-
});
122-
self.addEventListener('fetch', (e) => {
123-
const req = e.request;
124-
if (req.method !== 'GET') return;
125-
const url = new URL(req.url);
126-
if (url.origin !== self.location.origin) return;
127-
if (url.pathname.startsWith('/api/')) return;
128-
if (req.mode === 'navigate') {
129-
e.respondWith(
130-
fetch(req).then((res) => {
131-
const copy = res.clone();
132-
caches.open(CACHE).then((c) => c.put(req, copy));
133-
return res;
134-
}).catch(() => caches.match(req).then((r) => r || caches.match('/')))
135-
);
136-
return;
137-
}
138-
e.respondWith(
139-
caches.match(req).then((cached) => cached || fetch(req).then((res) => {
140-
if (res.ok && res.type === 'basic') {
141-
const copy = res.clone();
142-
caches.open(CACHE).then((c) => c.put(req, copy));
143-
}
144-
return res;
145-
}))
146-
);
147-
});
148-
`;
149-
await emit('sw.js', sw);
150-
15190
// robots.txt verbatim.
15291
await emit('robots.txt', await fs.readFile(path.join(root, 'robots.txt')));
15392

154-
// _headers + immutable caching for hashed assets, no-cache for entry/sw.
93+
// _headers + immutable caching for hashed assets, no-cache for entry.
15594
const headers = await fs.readFile(path.join(root, '_headers'), 'utf8');
15695
const cacheRules = `
15796
15897
/js/*
15998
Cache-Control: public, max-age=31536000, immutable
16099
/css/*
161100
Cache-Control: public, max-age=31536000, immutable
162-
/sw.js
163-
Cache-Control: no-cache
164101
/index.html
165102
Cache-Control: no-cache
166103
/
167104
Cache-Control: no-cache
168105
`;
169106
await emit('_headers', headers.replace(/\s*$/, '') + cacheRules);
170107

171-
console.log(`Built ${assetMap.size + 1} assets to dist/ (cache nym-${version}, ${precache.length} precached).`);
108+
console.log(`Built ${assetMap.size} assets to dist/.`);
172109
}
173110

174111
run().catch((e) => { console.error(e); process.exit(1); });

js/modules/pms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,7 @@ Object.assign(NYM.prototype, {
20702070
? `<span class="verified-badge" title="${this.verifiedBot.title}">✓</span>`
20712071
: '';
20722072
const displayNym = `${this.escapeHtml(baseNym)}<span class="nym-suffix">#${suffix}</span>${flairHtml}${verifiedBadge}${friendBadge}`;
2073-
const pmHeaderHtml = `<img src="${this.escapeHtml(pmAvatarSrc)}" class="avatar-message" data-avatar-pubkey="${safePk}" alt="" loading="lazy">@${displayNym} <span class="nm-pms-1">(PM)</span>`;
2073+
const pmHeaderHtml = `<img src="${this.escapeHtml(pmAvatarSrc)}" class="avatar-message" data-avatar-pubkey="${safePk}" alt="" loading="lazy">${displayNym} <span class="nm-pms-1">(PM)</span>`;
20742074

20752075
// Update UI with formatted nym
20762076
const _pmHeaderEl = document.getElementById('currentChannel');

js/modules/users.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ Object.assign(NYM.prototype, {
17871787
if (channelEl.dataset.pmHeaderSig !== sig) {
17881788
const pmAvatarSrc = this.getAvatarUrl(pubkey);
17891789
const displayNym = `${this.escapeHtml(baseNym)}<span class="nym-suffix">#${suffix}</span>${flairHtml}${friendBadge}`;
1790-
channelEl.innerHTML = `<img src="${this.escapeHtml(pmAvatarSrc)}" class="avatar-message" data-avatar-pubkey="${safePk}" alt="" loading="lazy">@${displayNym} <span class="nm-usr-2">(PM)</span>`;
1790+
channelEl.innerHTML = `<img src="${this.escapeHtml(pmAvatarSrc)}" class="avatar-message" data-avatar-pubkey="${safePk}" alt="" loading="lazy">${displayNym} <span class="nm-usr-2">(PM)</span>`;
17911791
channelEl.dataset.pmHeaderSig = sig;
17921792
}
17931793
}

0 commit comments

Comments
 (0)