Skip to content
This repository was archived by the owner on Jul 15, 2025. It is now read-only.

Aum / spike / PWA#105

Closed
aum-deriv wants to merge 2 commits intomasterfrom
spike-pwa
Closed

Aum / spike / PWA#105
aum-deriv wants to merge 2 commits intomasterfrom
spike-pwa

Conversation

@aum-deriv
Copy link
Contributor

@aum-deriv aum-deriv commented Mar 21, 2025

Summary by Sourcery

Adds Progressive Web App (PWA) functionality to the application, enabling offline access and installability.

New Features:

  • Implements PWA functionality, allowing users to install the app and use it offline.
  • Adds a service worker for caching static assets and handling network requests.
  • Provides an offline page to display when the user is offline.
  • Adds a manifest file to configure the PWA's appearance and behavior.
  • Registers the service worker to enable caching and offline functionality.
  • Adds utility functions for handling offline functionality, such as checking online status and retrieving cached data.
  • Adds cache strategy definitions for different types of assets, including static assets, dynamic content, images, and API responses.
  • Adds offline fallbacks for specific route patterns.

@devloai
Copy link

devloai bot commented Mar 21, 2025

Unable to perform a code review. You have run out of credits 😔

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 21, 2025

Reviewer's Guide by Sourcery

This pull request implements a Progressive Web App (PWA) setup. It includes adding Workbox dependencies, configuring meta tags and a manifest file, registering a service worker, and creating an offline page. The service worker caches static assets and serves them when the user is offline, providing a better user experience.

Sequence diagram for service worker registration

sequenceDiagram
    participant Browser
    participant ServiceWorkerRegistration
    participant ServiceWorker

    Browser->>ServiceWorkerRegistration: register('/service-worker.js')
    activate ServiceWorkerRegistration
    ServiceWorkerRegistration-->>Browser: Registration object
    deactivate ServiceWorkerRegistration

    Browser->>ServiceWorker: Install event
    activate ServiceWorker
    ServiceWorker->>CacheStorage: Open cache
    activate CacheStorage
    CacheStorage-->>ServiceWorker: Cache object
    deactivate CacheStorage
    ServiceWorker->>Cache: Add static assets
    activate Cache
    Cache-->>ServiceWorker: Success
    deactivate Cache
    ServiceWorker-->>Browser: Installation complete
    deactivate ServiceWorker

    Browser->>ServiceWorker: Activate event
    activate ServiceWorker
    ServiceWorker->>CacheStorage: Get cache keys
    activate CacheStorage
    CacheStorage-->>ServiceWorker: Cache keys
    deactivate CacheStorage
    ServiceWorker->>CacheStorage: Delete old caches
    activate CacheStorage
    CacheStorage-->>ServiceWorker: Success
    deactivate CacheStorage
    ServiceWorker-->>Browser: Activation complete
    deactivate ServiceWorker
Loading

File-Level Changes

Change Details Files
Added dependencies for Workbox, a set of libraries that help with creating Progressive Web Apps.
  • Added 'workbox-core', 'workbox-expiration', 'workbox-precaching', 'workbox-routing', and 'workbox-strategies' as dependencies.
  • Added 'workbox-webpack-plugin' as a dev dependency.
package.json
Configured the application as a PWA by adding meta tags and a manifest file.
  • Added meta tags for description, theme color, and apple mobile web app configuration.
  • Added links to the manifest file and apple touch icon.
index.html
Registered the service worker to enable offline capabilities.
  • Imported the service worker registration script.
  • Registered the service worker.
src/index.tsx
Implemented service worker registration logic.
  • Added logic to register the service worker.
  • Included checks for localhost and production environments.
  • Added handling for service worker updates and caching.
  • Added unregister function to disable service worker.
src/pwa/serviceWorkerRegistration.ts
Added utility functions for handling offline functionality.
  • Added function to check if the user is offline.
  • Added function to add and remove connectivity listeners.
  • Added React hook for monitoring online/offline status.
  • Added function to detect if the app is running in standalone mode.
  • Added function to check if the service worker is active.
  • Added function to retrieve cached data for a specific URL.
  • Added function to show an offline notification to the user.
src/pwa/offlineUtils.ts
Defined cache strategy definitions for different types of assets.
  • Defined cache names for static assets, dynamic content, images, and API.
  • Defined URLs to precache.
  • Defined URLs to cache with network-first, cache-first, and stale-while-revalidate strategies.
  • Defined URLs that should never be cached.
  • Defined offline fallback mapping.
  • Defined maximum age for cached resources.
  • Added helper function to determine cache strategy based on URL.
src/pwa/cacheStrategies.ts
Created a basic service worker for PWA.
  • Defined cache name and static assets to cache.
  • Added install event listener to cache static assets.
  • Added activate event listener to clean up old caches.
  • Added fetch event listener to serve from cache or network.
public/service-worker.js
Created an offline page to display when the user is offline.
  • Added basic HTML structure and styling for the offline page.
  • Included a message to inform the user that they are offline.
  • Added a button to retry the connection.
public/offline.html
Created a manifest file to configure the PWA.
  • Defined the name, short name, description, start URL, display mode, background color, theme color, and icons for the PWA.
public/manifest.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions
Copy link

github-actions bot commented Mar 21, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

Scorecard details
PackageVersionScoreDetails
npm/idb 7.1.1 🟢 4
Details
CheckScoreReason
Code-Review⚠️ 2Found 7/30 approved changesets -- score normalized to 2
Dangerous-Workflow⚠️ -1no workflows found
Packaging⚠️ -1packaging workflow not detected
Maintained🟢 53 commit(s) and 4 issue activity found in the last 90 days -- score normalized to 5
Token-Permissions⚠️ -1No tokens found
Binary-Artifacts🟢 10no binaries found in the repo
Pinned-Dependencies⚠️ -1no dependencies found
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Security-Policy⚠️ 0security policy file not detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Signed-Releases⚠️ -1no releases found
Branch-Protection⚠️ 0branch protection not enabled on development/release branches
Vulnerabilities🟢 100 existing vulnerabilities detected
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0
npm/workbox-core 7.3.0 🟢 4.2
Details
CheckScoreReason
Binary-Artifacts🟢 9binaries present in source code
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by personal access token
CI-Tests🟢 88 out of 10 merged PRs checked by a CI test -- score normalized to 8
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Code-Review🟢 4found 9 unreviewed changesets out of 16 -- score normalized to 4
Contributors🟢 1043 different organizations found -- score normalized to 10
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Dependency-Update-Tool⚠️ 0no update tool detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Maintained🟢 1011 commit(s) out of 30 and 9 issue activity out of 30 found in the last 90 days -- score normalized to 10
Packaging⚠️ -1no published package detected
Pinned-Dependencies🟢 3dependency not pinned by hash detected -- score normalized to 3
SAST🟢 6SAST tool is not run on all commits -- score normalized to 6
Security-Policy⚠️ 0security policy file not detected
Signed-Releases⚠️ 00 out of 5 artifacts are signed or have provenance
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Vulnerabilities⚠️ 022 existing vulnerabilities detected
npm/workbox-expiration 7.3.0 🟢 4.2
Details
CheckScoreReason
Binary-Artifacts🟢 9binaries present in source code
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by personal access token
CI-Tests🟢 88 out of 10 merged PRs checked by a CI test -- score normalized to 8
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Code-Review🟢 4found 9 unreviewed changesets out of 16 -- score normalized to 4
Contributors🟢 1043 different organizations found -- score normalized to 10
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Dependency-Update-Tool⚠️ 0no update tool detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Maintained🟢 1011 commit(s) out of 30 and 9 issue activity out of 30 found in the last 90 days -- score normalized to 10
Packaging⚠️ -1no published package detected
Pinned-Dependencies🟢 3dependency not pinned by hash detected -- score normalized to 3
SAST🟢 6SAST tool is not run on all commits -- score normalized to 6
Security-Policy⚠️ 0security policy file not detected
Signed-Releases⚠️ 00 out of 5 artifacts are signed or have provenance
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Vulnerabilities⚠️ 022 existing vulnerabilities detected
npm/workbox-precaching 7.3.0 🟢 4.2
Details
CheckScoreReason
Binary-Artifacts🟢 9binaries present in source code
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by personal access token
CI-Tests🟢 88 out of 10 merged PRs checked by a CI test -- score normalized to 8
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Code-Review🟢 4found 9 unreviewed changesets out of 16 -- score normalized to 4
Contributors🟢 1043 different organizations found -- score normalized to 10
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Dependency-Update-Tool⚠️ 0no update tool detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Maintained🟢 1011 commit(s) out of 30 and 9 issue activity out of 30 found in the last 90 days -- score normalized to 10
Packaging⚠️ -1no published package detected
Pinned-Dependencies🟢 3dependency not pinned by hash detected -- score normalized to 3
SAST🟢 6SAST tool is not run on all commits -- score normalized to 6
Security-Policy⚠️ 0security policy file not detected
Signed-Releases⚠️ 00 out of 5 artifacts are signed or have provenance
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Vulnerabilities⚠️ 022 existing vulnerabilities detected
npm/workbox-routing 7.3.0 🟢 4.2
Details
CheckScoreReason
Binary-Artifacts🟢 9binaries present in source code
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by personal access token
CI-Tests🟢 88 out of 10 merged PRs checked by a CI test -- score normalized to 8
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Code-Review🟢 4found 9 unreviewed changesets out of 16 -- score normalized to 4
Contributors🟢 1043 different organizations found -- score normalized to 10
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Dependency-Update-Tool⚠️ 0no update tool detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Maintained🟢 1011 commit(s) out of 30 and 9 issue activity out of 30 found in the last 90 days -- score normalized to 10
Packaging⚠️ -1no published package detected
Pinned-Dependencies🟢 3dependency not pinned by hash detected -- score normalized to 3
SAST🟢 6SAST tool is not run on all commits -- score normalized to 6
Security-Policy⚠️ 0security policy file not detected
Signed-Releases⚠️ 00 out of 5 artifacts are signed or have provenance
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Vulnerabilities⚠️ 022 existing vulnerabilities detected
npm/workbox-strategies 7.3.0 🟢 4.2
Details
CheckScoreReason
Binary-Artifacts🟢 9binaries present in source code
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by personal access token
CI-Tests🟢 88 out of 10 merged PRs checked by a CI test -- score normalized to 8
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Code-Review🟢 4found 9 unreviewed changesets out of 16 -- score normalized to 4
Contributors🟢 1043 different organizations found -- score normalized to 10
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Dependency-Update-Tool⚠️ 0no update tool detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Maintained🟢 1011 commit(s) out of 30 and 9 issue activity out of 30 found in the last 90 days -- score normalized to 10
Packaging⚠️ -1no published package detected
Pinned-Dependencies🟢 3dependency not pinned by hash detected -- score normalized to 3
SAST🟢 6SAST tool is not run on all commits -- score normalized to 6
Security-Policy⚠️ 0security policy file not detected
Signed-Releases⚠️ 00 out of 5 artifacts are signed or have provenance
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Vulnerabilities⚠️ 022 existing vulnerabilities detected
npm/workbox-core ^7.3.0 🟢 4.2
Details
CheckScoreReason
Binary-Artifacts🟢 9binaries present in source code
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by personal access token
CI-Tests🟢 88 out of 10 merged PRs checked by a CI test -- score normalized to 8
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Code-Review🟢 4found 9 unreviewed changesets out of 16 -- score normalized to 4
Contributors🟢 1043 different organizations found -- score normalized to 10
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Dependency-Update-Tool⚠️ 0no update tool detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Maintained🟢 1011 commit(s) out of 30 and 9 issue activity out of 30 found in the last 90 days -- score normalized to 10
Packaging⚠️ -1no published package detected
Pinned-Dependencies🟢 3dependency not pinned by hash detected -- score normalized to 3
SAST🟢 6SAST tool is not run on all commits -- score normalized to 6
Security-Policy⚠️ 0security policy file not detected
Signed-Releases⚠️ 00 out of 5 artifacts are signed or have provenance
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Vulnerabilities⚠️ 022 existing vulnerabilities detected
npm/workbox-expiration ^7.3.0 🟢 4.2
Details
CheckScoreReason
Binary-Artifacts🟢 9binaries present in source code
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by personal access token
CI-Tests🟢 88 out of 10 merged PRs checked by a CI test -- score normalized to 8
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Code-Review🟢 4found 9 unreviewed changesets out of 16 -- score normalized to 4
Contributors🟢 1043 different organizations found -- score normalized to 10
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Dependency-Update-Tool⚠️ 0no update tool detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Maintained🟢 1011 commit(s) out of 30 and 9 issue activity out of 30 found in the last 90 days -- score normalized to 10
Packaging⚠️ -1no published package detected
Pinned-Dependencies🟢 3dependency not pinned by hash detected -- score normalized to 3
SAST🟢 6SAST tool is not run on all commits -- score normalized to 6
Security-Policy⚠️ 0security policy file not detected
Signed-Releases⚠️ 00 out of 5 artifacts are signed or have provenance
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Vulnerabilities⚠️ 022 existing vulnerabilities detected
npm/workbox-precaching ^7.3.0 🟢 4.2
Details
CheckScoreReason
Binary-Artifacts🟢 9binaries present in source code
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by personal access token
CI-Tests🟢 88 out of 10 merged PRs checked by a CI test -- score normalized to 8
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Code-Review🟢 4found 9 unreviewed changesets out of 16 -- score normalized to 4
Contributors🟢 1043 different organizations found -- score normalized to 10
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Dependency-Update-Tool⚠️ 0no update tool detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Maintained🟢 1011 commit(s) out of 30 and 9 issue activity out of 30 found in the last 90 days -- score normalized to 10
Packaging⚠️ -1no published package detected
Pinned-Dependencies🟢 3dependency not pinned by hash detected -- score normalized to 3
SAST🟢 6SAST tool is not run on all commits -- score normalized to 6
Security-Policy⚠️ 0security policy file not detected
Signed-Releases⚠️ 00 out of 5 artifacts are signed or have provenance
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Vulnerabilities⚠️ 022 existing vulnerabilities detected
npm/workbox-routing ^7.3.0 🟢 4.2
Details
CheckScoreReason
Binary-Artifacts🟢 9binaries present in source code
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by personal access token
CI-Tests🟢 88 out of 10 merged PRs checked by a CI test -- score normalized to 8
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Code-Review🟢 4found 9 unreviewed changesets out of 16 -- score normalized to 4
Contributors🟢 1043 different organizations found -- score normalized to 10
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Dependency-Update-Tool⚠️ 0no update tool detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Maintained🟢 1011 commit(s) out of 30 and 9 issue activity out of 30 found in the last 90 days -- score normalized to 10
Packaging⚠️ -1no published package detected
Pinned-Dependencies🟢 3dependency not pinned by hash detected -- score normalized to 3
SAST🟢 6SAST tool is not run on all commits -- score normalized to 6
Security-Policy⚠️ 0security policy file not detected
Signed-Releases⚠️ 00 out of 5 artifacts are signed or have provenance
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Vulnerabilities⚠️ 022 existing vulnerabilities detected
npm/workbox-strategies ^7.3.0 🟢 4.2
Details
CheckScoreReason
Binary-Artifacts🟢 9binaries present in source code
Branch-Protection⚠️ -1internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by personal access token
CI-Tests🟢 88 out of 10 merged PRs checked by a CI test -- score normalized to 8
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Code-Review🟢 4found 9 unreviewed changesets out of 16 -- score normalized to 4
Contributors🟢 1043 different organizations found -- score normalized to 10
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Dependency-Update-Tool⚠️ 0no update tool detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Maintained🟢 1011 commit(s) out of 30 and 9 issue activity out of 30 found in the last 90 days -- score normalized to 10
Packaging⚠️ -1no published package detected
Pinned-Dependencies🟢 3dependency not pinned by hash detected -- score normalized to 3
SAST🟢 6SAST tool is not run on all commits -- score normalized to 6
Security-Policy⚠️ 0security policy file not detected
Signed-Releases⚠️ 00 out of 5 artifacts are signed or have provenance
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Vulnerabilities⚠️ 022 existing vulnerabilities detected

Scanned Manifest Files

package-lock.json
  • @apideck/better-ajv-errors@0.3.6
  • @babel/helper-annotate-as-pure@7.25.9
  • @babel/helper-create-class-features-plugin@7.26.9
  • @babel/helper-create-regexp-features-plugin@7.26.3
  • @babel/helper-define-polyfill-provider@0.6.4
  • @babel/helper-member-expression-to-functions@7.25.9
  • @babel/helper-optimise-call-expression@7.25.9
  • @babel/helper-remap-async-to-generator@7.25.9
  • @babel/helper-replace-supers@7.26.5
  • @babel/helper-skip-transparent-expression-wrappers@7.25.9
  • @babel/helper-wrap-function@7.25.9
  • @babel/plugin-bugfix-firefox-class-in-computed-class-key@7.25.9
  • @babel/plugin-bugfix-safari-class-field-initializer-scope@7.25.9
  • @babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@7.25.9
  • @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@7.25.9
  • @babel/plugin-bugfix-v8-static-class-fields-redefine-readonly@7.25.9
  • @babel/plugin-proposal-private-property-in-object@7.21.0-placeholder-for-preset-env.2
  • @babel/plugin-syntax-import-assertions@7.26.0
  • @babel/plugin-syntax-unicode-sets-regex@7.18.6
  • @babel/plugin-transform-arrow-functions@7.25.9
  • @babel/plugin-transform-async-generator-functions@7.26.8
  • @babel/plugin-transform-async-to-generator@7.25.9
  • @babel/plugin-transform-block-scoped-functions@7.26.5
  • @babel/plugin-transform-block-scoping@7.25.9
  • @babel/plugin-transform-class-properties@7.25.9
  • @babel/plugin-transform-class-static-block@7.26.0
  • @babel/plugin-transform-classes@7.25.9
  • @babel/plugin-transform-computed-properties@7.25.9
  • @babel/plugin-transform-destructuring@7.25.9
  • @babel/plugin-transform-dotall-regex@7.25.9
  • @babel/plugin-transform-duplicate-keys@7.25.9
  • @babel/plugin-transform-duplicate-named-capturing-groups-regex@7.25.9
  • @babel/plugin-transform-dynamic-import@7.25.9
  • @babel/plugin-transform-exponentiation-operator@7.26.3
  • @babel/plugin-transform-export-namespace-from@7.25.9
  • @babel/plugin-transform-for-of@7.26.9
  • @babel/plugin-transform-function-name@7.25.9
  • @babel/plugin-transform-json-strings@7.25.9
  • @babel/plugin-transform-literals@7.25.9
  • @babel/plugin-transform-logical-assignment-operators@7.25.9
  • @babel/plugin-transform-member-expression-literals@7.25.9
  • @babel/plugin-transform-modules-amd@7.25.9
  • @babel/plugin-transform-modules-commonjs@7.26.3
  • @babel/plugin-transform-modules-systemjs@7.25.9
  • @babel/plugin-transform-modules-umd@7.25.9
  • @babel/plugin-transform-named-capturing-groups-regex@7.25.9
  • @babel/plugin-transform-new-target@7.25.9
  • @babel/plugin-transform-nullish-coalescing-operator@7.26.6
  • @babel/plugin-transform-numeric-separator@7.25.9
  • @babel/plugin-transform-object-rest-spread@7.25.9
  • @babel/plugin-transform-object-super@7.25.9
  • @babel/plugin-transform-optional-catch-binding@7.25.9
  • @babel/plugin-transform-optional-chaining@7.25.9
  • @babel/plugin-transform-parameters@7.25.9
  • @babel/plugin-transform-private-methods@7.25.9
  • @babel/plugin-transform-private-property-in-object@7.25.9
  • @babel/plugin-transform-property-literals@7.25.9
  • @babel/plugin-transform-regenerator@7.25.9
  • @babel/plugin-transform-regexp-modifiers@7.26.0
  • @babel/plugin-transform-reserved-words@7.25.9
  • @babel/plugin-transform-shorthand-properties@7.25.9
  • @babel/plugin-transform-spread@7.25.9
  • @babel/plugin-transform-sticky-regex@7.25.9
  • @babel/plugin-transform-template-literals@7.26.8
  • @babel/plugin-transform-typeof-symbol@7.26.7
  • @babel/plugin-transform-unicode-escapes@7.25.9
  • @babel/plugin-transform-unicode-property-regex@7.25.9
  • @babel/plugin-transform-unicode-regex@7.25.9
  • @babel/plugin-transform-unicode-sets-regex@7.25.9
  • @babel/preset-env@7.26.9
  • @babel/preset-modules@0.1.6-no-external-plugins
  • @jridgewell/source-map@0.3.6
  • @rollup/plugin-babel@5.3.1
  • @rollup/plugin-node-resolve@15.3.1
  • @rollup/plugin-replace@2.4.2
  • @rollup/plugin-terser@0.4.4
  • @rollup/pluginutils@5.1.4
  • @rollup/pluginutils@3.1.0
  • @surma/rollup-plugin-off-main-thread@2.2.3
  • @types/eslint@9.6.1
  • @types/eslint-scope@3.7.7
  • @types/estree@0.0.39
  • @types/estree@1.0.6
  • @types/resolve@1.20.2
  • @types/trusted-types@2.0.7
  • @webassemblyjs/ast@1.14.1
  • @webassemblyjs/floating-point-hex-parser@1.13.2
  • @webassemblyjs/helper-api-error@1.13.2
  • @webassemblyjs/helper-buffer@1.14.1
  • @webassemblyjs/helper-numbers@1.13.2
  • @webassemblyjs/helper-wasm-bytecode@1.13.2
  • @webassemblyjs/helper-wasm-section@1.14.1
  • @webassemblyjs/ieee754@1.13.2
  • @webassemblyjs/leb128@1.13.2
  • @webassemblyjs/utf8@1.13.2
  • @webassemblyjs/wasm-edit@1.14.1
  • @webassemblyjs/wasm-gen@1.14.1
  • @webassemblyjs/wasm-opt@1.14.1
  • @webassemblyjs/wasm-parser@1.14.1
  • @webassemblyjs/wast-printer@1.14.1
  • @xtuc/ieee754@1.2.0
  • @xtuc/long@4.2.2
  • arraybuffer.prototype.slice@1.0.4
  • async-function@1.0.0
  • at-least-node@1.0.0
  • babel-plugin-polyfill-corejs2@0.4.13
  • babel-plugin-polyfill-corejs3@0.11.1
  • babel-plugin-polyfill-regenerator@0.6.4
  • chrome-trace-event@1.0.4
  • commander@2.20.3
  • common-tags@1.8.2
  • core-js-compat@3.41.0
  • crypto-random-string@2.0.0
  • data-view-buffer@1.0.2
  • data-view-byte-length@1.0.2
  • data-view-byte-offset@1.0.1
  • enhanced-resolve@5.18.1
  • es-abstract@1.23.9
  • es-module-lexer@1.6.0
  • es-to-primitive@1.3.0
  • eslint-scope@5.1.1
  • estraverse@4.3.0
  • estree-walker@2.0.2
  • estree-walker@1.0.1
  • events@3.3.0
  • fs-extra@9.1.0
  • function.prototype.name@1.1.8
  • get-own-enumerable-property-symbols@3.0.2
  • get-symbol-description@1.1.0
  • glob-to-regexp@0.4.1
  • globalthis@1.0.4
  • has-proto@1.2.0
  • idb@7.1.1
  • is-async-function@2.1.1
  • is-data-view@1.0.2
  • is-finalizationregistry@1.1.1
  • is-generator-function@1.1.0
  • is-module@1.0.0
  • is-obj@1.0.1
  • is-regexp@1.0.0
  • is-typed-array@1.1.15
  • is-weakref@1.1.1
  • jest-worker@27.5.1
  • jsesc@3.0.2
  • json-schema@0.4.0
  • jsonfile@6.1.0
  • jsonpointer@5.0.1
  • loader-runner@4.3.0
  • lodash.sortby@4.7.0
  • magic-string@0.25.9
  • neo-async@2.6.2
  • own-keys@1.0.1
  • picomatch@4.0.2
  • pretty-bytes@5.6.0
  • randombytes@2.1.0
  • reflect.getprototypeof@1.0.10
  • regenerate@1.4.2
  • regenerate-unicode-properties@10.2.0
  • regenerator-transform@0.15.2
  • regexpu-core@6.2.0
  • regjsgen@0.8.0
  • regjsparser@0.12.0
  • rollup@2.79.2
  • safe-array-concat@1.1.3
  • safe-push-apply@1.0.0
  • serialize-javascript@6.0.2
  • set-proto@1.0.0
  • smob@1.5.0
  • source-list-map@2.0.1
  • source-map@0.8.0-beta.0
  • source-map-support@0.5.21
  • sourcemap-codec@1.4.8
  • string.prototype.matchall@4.0.12
  • string.prototype.trim@1.2.10
  • string.prototype.trimend@1.0.9
  • string.prototype.trimstart@1.0.8
  • stringify-object@3.3.0
  • strip-comments@2.0.1
  • tapable@2.2.1
  • temp-dir@2.0.0
  • tempy@0.6.0
  • terser@5.39.0
  • terser-webpack-plugin@5.3.14
  • tr46@1.0.1
  • type-fest@0.16.0
  • typed-array-buffer@1.0.3
  • typed-array-byte-length@1.0.3
  • typed-array-byte-offset@1.0.4
  • typed-array-length@1.0.7
  • unbox-primitive@1.1.0
  • unicode-canonical-property-names-ecmascript@2.0.1
  • unicode-match-property-ecmascript@2.0.0
  • unicode-match-property-value-ecmascript@2.2.0
  • unicode-property-aliases-ecmascript@2.1.0
  • unique-string@2.0.0
  • universalify@2.0.1
  • upath@1.2.0
  • watchpack@2.4.2
  • webidl-conversions@4.0.2
  • webpack@5.98.0
  • webpack-sources@3.2.3
  • webpack-sources@1.4.3
  • whatwg-url@7.1.0
  • which-builtin-type@1.2.1
  • workbox-background-sync@7.3.0
  • workbox-broadcast-update@7.3.0
  • workbox-build@7.3.0
  • workbox-cacheable-response@7.3.0
  • workbox-core@7.3.0
  • workbox-expiration@7.3.0
  • workbox-google-analytics@7.3.0
  • workbox-navigation-preload@7.3.0
  • workbox-precaching@7.3.0
  • workbox-range-requests@7.3.0
  • workbox-recipes@7.3.0
  • workbox-routing@7.3.0
  • workbox-strategies@7.3.0
  • workbox-streams@7.3.0
  • workbox-sw@7.3.0
  • workbox-webpack-plugin@7.3.0
  • workbox-window@7.3.0
package.json
  • workbox-core@^7.3.0
  • workbox-expiration@^7.3.0
  • workbox-precaching@^7.3.0
  • workbox-routing@^7.3.0
  • workbox-strategies@^7.3.0
  • workbox-webpack-plugin@^7.3.0

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 21, 2025

Deploying champion-trader with  Cloudflare Pages  Cloudflare Pages

Latest commit: bda0d68
Status: ✅  Deploy successful!
Preview URL: https://d1fd7912.champion-trader.pages.dev
Branch Preview URL: https://spike-pwa.champion-trader.pages.dev

View logs

@aum-deriv aum-deriv changed the title feat: pwa setup Aum / spike / PWA Mar 21, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @aum-deriv - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using a build tool plugin like WorkboxWebpackPlugin to generate the service worker file instead of manually creating it.
  • The service worker registration code includes a check for localhost, which might not be necessary in all environments.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

onUpdate?: (registration: ServiceWorkerRegistration) => void;
};

export function register(config?: Config): void {
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider refactoring the asynchronous logic using async/await and extracting common functionality to reduce nested control flow and improve readability.

Consider reducing the nested control flow by refactoring the asynchronous logic into async/await functions and extracting common functionality. For example, you can refactor the registration functions to avoid double branching and nested callbacks. One approach is:

async function registerValidSW(swUrl: string, config?: Config): Promise<void> {
  try {
    const registration = await navigator.serviceWorker.register(swUrl);
    registration.onupdatefound = () => {
      const installingWorker = registration.installing;
      if (!installingWorker) return;

      installingWorker.onstatechange = () => {
        if (installingWorker.state !== "installed") return;

        if (navigator.serviceWorker.controller) {
          console.log(
            "New content is available and will be used when all tabs are closed. See https://cra.link/PWA."
          );
          config?.onUpdate?.(registration);
        } else {
          console.log("Content is cached for offline use.");
          config?.onSuccess?.(registration);
        }
      };
    };
  } catch (error) {
    console.error("Error during service worker registration:", error);
  }
}

Similarly, refactor checkValidServiceWorker to reduce nesting:

async function checkValidServiceWorker(swUrl: string, config?: Config): Promise<void> {
  try {
    const response = await fetch(swUrl, { headers: { "Service-Worker": "script" } });
    const contentType = response.headers.get("content-type");

    if (
      response.status === 404 ||
      (contentType && contentType.indexOf("javascript") === -1)
    ) {
      const registration = await navigator.serviceWorker.ready;
      await registration.unregister();
      window.location.reload();
    } else {
      // Found a valid service worker so proceed with registration.
      await registerValidSW(swUrl, config);
    }
  } catch {
    console.log("No internet connection found. App is running in offline mode.");
  }
}

Then, in your register function, the flow becomes simpler:

export function register(config?: Config): void {
  if ("serviceWorker" in navigator) {
    const publicUrl = new URL("", window.location.href);
    if (publicUrl.origin !== window.location.origin) return;

    window.addEventListener("load", () => {
      const swUrl = "/service-worker.js";
      if (isLocalhost) {
        checkValidServiceWorker(swUrl, config);
        navigator.serviceWorker.ready.then(() => {
          console.log(
            "This web app is being served cache-first by a service worker. To learn more, visit https://cra.link/PWA"
          );
        });
      } else {
        registerValidSW(swUrl, config);
      }
    });
  }
}

This approach reduces nesting, keeps the functionality intact, and makes maintenance easier.

@aum-deriv aum-deriv marked this pull request as draft March 21, 2025 10:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants