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

Use serwist to handle service worker #1355

Merged
merged 4 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ yarn-error.log*
# local env files
.env*.local

# PWA artifacts
**/public/sw.js*
**/public/fallback-*.js*
**/public/workbox-*.js*
**/public/worker-*.js*
# Serwist
**/public/sw*
**/public/swe-worker*

# typescript
*.tsbuildinfo
Expand Down
1 change: 0 additions & 1 deletion frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ RUN adduser -S nextjs -u 1001

# You only need to copy next.config.mjs if you are NOT using the default configuration
COPY --from=builder /app/next.config.mjs ./
COPY --from=builder /app/cache.js ./
COPY --from=builder /app/config ./config
COPY --chown=nextjs:nodejs --from=builder /app/src/ ./src
COPY --from=builder_optim /app/node_modules ./node_modules
Expand Down
188 changes: 0 additions & 188 deletions frontend/cache.js

This file was deleted.

14 changes: 8 additions & 6 deletions frontend/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import path from 'path';
import withPlugins from 'next-compose-plugins';
import withSourceMaps from '@zeit/next-source-maps';
import dotenv from 'dotenv-flow';
import runtimeCachingStrategy from './cache.js';
import { runtimeConfig } from './src/services/getConfig.mjs';
import { withSentryConfig } from '@sentry/nextjs';
import withPWA from 'next-pwa';
import withSerwistInit from '@serwist/next';

withPWA({
const withSerwist = withSerwistInit({
cacheOnNavigation: true,
swSrc: 'worker/sw.ts',
swDest: 'public/sw.js',
scope: '/',
disable: process.env.NODE_ENV === 'development',
dest: 'public',
runtimeCaching: runtimeCachingStrategy,
additionalPrecacheEntries: [{ url: '/offline', revision: crypto.randomUUID() }],
});

const env = dotenv.config().parsed;
Expand All @@ -19,7 +21,6 @@ const withBundleAnalyzer =
process.env.ANALYZE === 'true' ? (await import('@next/bundle-analyzer')).default() : x => x;

const plugins = [
[withPWA],
[withSourceMaps()],
[withBundleAnalyzer],
nextConfig =>
Expand All @@ -29,6 +30,7 @@ const plugins = [
disableClientWebpackPlugin: true,
silent: true,
}),
nextConfig => withSerwist(nextConfig),
];

/** @type {import('next').NextConfig} */
Expand Down
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@raruto/leaflet-elevation": "1.9.0",
"@react-hook/resize-observer": "^2.0.2",
"@sentry/nextjs": "^8.32.0",
"@serwist/next": "^9.0.11",
"@tanstack/react-query": "^5.51.1",
"@tanstack/react-query-devtools": "^5.51.1",
"@zeit/next-source-maps": "^0.0.4-canary.1",
Expand All @@ -62,7 +63,6 @@
"next": "^14.2.15",
"next-compose-plugins": "^2.2.1",
"next-leaflet-cluster": "^1.0.0",
"next-pwa": "^5.6.0",
"orejime": "^2.3.0",
"postcss": "8.3.6",
"react": "^18.3.1",
Expand Down Expand Up @@ -123,6 +123,7 @@
"nock": "13.1.3",
"prettier": "^3.2.5",
"react-addons-test-utils": "^15.6.2",
"serwist": "^9.0.11",
"stylelint": "13.13.1",
"stylelint-config-prettier": "^8.0.2",
"stylelint-config-standard": "22.0.0",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
<div className="h-11 desktop:h-desktopHeader flex justify-between items-center sticky z-header px-3 shadow-sm shrink-0 transition-all duration-300 delay-100">
<Link href={routes.HOME} className="flex items-center">
<div className="shrink-0" id="header_logo">
<img

Check warning on line 32 in frontend/src/components/Header/Header.tsx

View workflow job for this annotation

GitHub Actions / install-and-test

Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element
id="header_logoImg"
className="h-9 w-auto desktop:h-18 mr-3"
alt=""
crossOrigin="anonymous"
src={config.logo}
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/ImageWithLegend/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@
legend={legend}
className={`relative h-full ${className}`}
>
<img

Check warning on line 36 in frontend/src/components/ImageWithLegend/index.tsx

View workflow job for this annotation

GitHub Actions / install-and-test

Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element
alt={image.legend || ''}
className={cn(`object-cover object-center overflow-hidden size-full ${classNameImage}`)}
id={imageId}
loading={loading ?? 'eager'}
src={image.url || getGlobalConfig().fallbackImageUri}
crossOrigin="anonymous"
/>
<Legend
figureId={figureId}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/InlineMenu/InlineMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const InlineMenu: React.FC<InlineMenuProps> = ({
height={16}
width={16}
svg
crossOrigin="anonymous"
/>
{language.toUpperCase()}
<ChevronDown size={16} className="shrink-0 ml-1" aria-hidden />
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Map/Markers/TrekMarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const ActivityMarker: React.FC<{
src={icon}
width={markerWidth * zoomRatio}
height={markerWidth * zoomRatio}
crossOrigin="anonymous"
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Object {
<img
alt="Lorem ipsum"
class="object-cover overflow-hidden size-full object-center"
crossorigin="anonymous"
id=":r3:"
loading="eager"
src="https://cdn.pixabay.com/photo/2017/06/29/18/40/background-2455710_400.jpg"
Expand Down Expand Up @@ -170,6 +171,7 @@ Object {
<img
alt="Lorem ipsum"
class="overflow-hidden size-full object-cover object-center"
crossorigin="anonymous"
id=":r9:"
loading="lazy"
src="https://cdn.pixabay.com/photo/2017/06/29/18/40/background-2455710_400.jpg"
Expand Down Expand Up @@ -229,6 +231,7 @@ Object {
<img
alt="Lorem ipsum"
class="overflow-hidden size-full object-cover object-center"
crossorigin="anonymous"
id=":rb:"
loading="lazy"
src="https://cdn.pixabay.com/photo/2017/06/29/18/40/background-2455710_400.jpg"
Expand Down Expand Up @@ -369,6 +372,7 @@ Object {
<img
alt="Lorem ipsum"
class="object-cover overflow-hidden size-full object-center"
crossorigin="anonymous"
id=":r3:"
loading="eager"
src="https://cdn.pixabay.com/photo/2017/06/29/18/40/background-2455710_400.jpg"
Expand Down Expand Up @@ -526,6 +530,7 @@ Object {
<img
alt="Lorem ipsum"
class="object-cover overflow-hidden size-full object-center"
crossorigin="anonymous"
id=":r3:"
loading="eager"
src="https://cdn.pixabay.com/photo/2017/06/29/18/40/background-2455710_400.jpg"
Expand Down Expand Up @@ -661,6 +666,7 @@ Object {
<img
alt="Lorem ipsum"
class="overflow-hidden size-full object-cover object-center"
crossorigin="anonymous"
id=":r9:"
loading="lazy"
src="https://cdn.pixabay.com/photo/2017/06/29/18/40/background-2455710_400.jpg"
Expand Down Expand Up @@ -720,6 +726,7 @@ Object {
<img
alt="Lorem ipsum"
class="overflow-hidden size-full object-cover object-center"
crossorigin="anonymous"
id=":rb:"
loading="lazy"
src="https://cdn.pixabay.com/photo/2017/06/29/18/40/background-2455710_400.jpg"
Expand Down Expand Up @@ -896,6 +903,7 @@ Object {
<img
alt="Lorem ipsum"
class="overflow-hidden size-full object-cover object-center"
crossorigin="anonymous"
id=":r9:"
loading="lazy"
src="https://cdn.pixabay.com/photo/2017/06/29/18/40/background-2455710_400.jpg"
Expand Down Expand Up @@ -955,6 +963,7 @@ Object {
<img
alt="Lorem ipsum"
class="overflow-hidden size-full object-cover object-center"
crossorigin="anonymous"
id=":rb:"
loading="lazy"
src="https://cdn.pixabay.com/photo/2017/06/29/18/40/background-2455710_400.jpg"
Expand Down
Loading
Loading