Skip to content

Commit

Permalink
feat(next-pwa): better offline support for App Router, extendDefaultR…
Browse files Browse the repository at this point in the history
…untimeCaching

[bump]
  • Loading branch information
DuCanhGH committed May 24, 2023
1 parent c827a70 commit 286f347
Show file tree
Hide file tree
Showing 22 changed files with 741 additions and 751 deletions.
7 changes: 7 additions & 0 deletions .changeset/heavy-pets-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@ducanh2912/next-pwa": minor
---

feat(next-pwa): better offline support for `app`

- This update helps improve offline support for App Router by caching RSC prefetches separately from other RSC requests.
9 changes: 9 additions & 0 deletions .changeset/tidy-walls-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@ducanh2912/next-pwa": minor
---

feat(next-pwa): added support for extending the default `runtimeCaching` array

- To use this feature you can add `extendDefaultRuntimeCaching` to your configuration.

- This feature helps you easily extend the default `runtimeCaching` array without having to copy the whole thing to your config. Your `runtimeCaching` have priority over the default runtime caching array, so its entries will override the default `runtimeCaching`'s entries should any of them share `cacheName`.
12 changes: 6 additions & 6 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
},
"dependencies": {
"@ducanh2912/next-pwa": "latest",
"next": "13.4.1",
"next": "13.4.3",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "20.1.1",
"@types/react": "18.2.6",
"@types/node": "20.2.3",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"eslint": "8.40.0",
"eslint-config-next": "13.4.1",
"eslint": "8.41.0",
"eslint-config-next": "13.4.3",
"typescript": "5.0.4",
"webpack": "5.82.0"
"webpack": "5.84.0"
}
}
12 changes: 6 additions & 6 deletions examples/cookie/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
"dependencies": {
"@ducanh2912/next-pwa": "latest",
"cookies-next": "2.1.1",
"next": "13.4.1",
"next": "13.4.3",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "20.1.1",
"@types/react": "18.2.6",
"@types/node": "20.2.3",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"eslint": "8.40.0",
"eslint-config-next": "13.4.1",
"eslint": "8.41.0",
"eslint-config-next": "13.4.3",
"typescript": "5.0.4",
"webpack": "5.82.0"
"webpack": "5.84.0"
}
}
18 changes: 9 additions & 9 deletions examples/custom-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
},
"dependencies": {
"@ducanh2912/next-pwa": "latest",
"@fastify/compress": "6.2.1",
"@fastify/compress": "6.3.0",
"cross-env": "7.0.3",
"fastify": "4.17.0",
"next": "13.4.1",
"next": "13.4.3",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@swc/core": "1.3.57",
"@types/node": "20.1.1",
"@types/react": "18.2.6",
"@swc/core": "1.3.59",
"@types/node": "20.2.3",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"eslint": "8.40.0",
"eslint-config-next": "13.4.1",
"eslint": "8.41.0",
"eslint-config-next": "13.4.3",
"nodemon": "2.0.22",
"rimraf": "5.0.0",
"rimraf": "5.0.1",
"ts-node": "10.9.1",
"typescript": "5.0.4",
"webpack": "5.82.0"
"webpack": "5.84.0"
}
}
12 changes: 6 additions & 6 deletions examples/custom-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
},
"dependencies": {
"@ducanh2912/next-pwa": "latest",
"next": "13.4.1",
"next": "13.4.3",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "20.1.1",
"@types/react": "18.2.6",
"@types/node": "20.2.3",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"eslint": "8.40.0",
"eslint-config-next": "13.4.1",
"eslint": "8.41.0",
"eslint-config-next": "13.4.3",
"typescript": "5.0.4",
"webpack": "5.82.0"
"webpack": "5.84.0"
}
}
12 changes: 6 additions & 6 deletions examples/lifecycle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
},
"dependencies": {
"@ducanh2912/next-pwa": "latest",
"next": "13.4.1",
"next": "13.4.3",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "20.1.1",
"@types/react": "18.2.6",
"@types/node": "20.2.3",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"eslint": "8.40.0",
"eslint-config-next": "13.4.1",
"eslint": "8.41.0",
"eslint-config-next": "13.4.3",
"typescript": "5.0.4",
"webpack": "5.82.0"
"webpack": "5.84.0"
}
}
16 changes: 8 additions & 8 deletions examples/next-i18next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
"cross-env": "7.0.3",
"express": "4.18.2",
"fastify-compress": "4.1.0",
"i18next": "22.4.15",
"next": "13.4.1",
"i18next": "22.5.0",
"next": "13.4.3",
"next-i18next": "13.2.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-i18next": "12.2.2"
"react-i18next": "12.3.1"
},
"devDependencies": {
"@types/node": "20.1.1",
"@types/react": "18.2.6",
"@types/node": "20.2.3",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"eslint": "8.40.0",
"eslint-config-next": "13.4.1",
"eslint": "8.41.0",
"eslint-config-next": "13.4.3",
"typescript": "5.0.4",
"webpack": "5.82.0"
"webpack": "5.84.0"
}
}
12 changes: 6 additions & 6 deletions examples/next-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
},
"dependencies": {
"@ducanh2912/next-pwa": "latest",
"next": "13.4.1",
"next": "13.4.3",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "20.1.1",
"@types/react": "18.2.6",
"@types/node": "20.2.3",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"eslint": "8.40.0",
"eslint-config-next": "13.4.1",
"eslint": "8.41.0",
"eslint-config-next": "13.4.3",
"typescript": "5.0.4",
"webpack": "5.82.0"
"webpack": "5.84.0"
}
}
12 changes: 6 additions & 6 deletions examples/offline-fallback-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
},
"dependencies": {
"@ducanh2912/next-pwa": "latest",
"next": "13.4.1",
"next": "13.4.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"sharp": "0.32.1"
},
"devDependencies": {
"@types/node": "20.1.1",
"@types/react": "18.2.6",
"@types/node": "20.2.3",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"eslint": "8.40.0",
"eslint-config-next": "13.4.1",
"eslint": "8.41.0",
"eslint-config-next": "13.4.3",
"typescript": "5.0.4",
"webpack": "5.82.0"
"webpack": "5.84.0"
}
}
12 changes: 6 additions & 6 deletions examples/web-push/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
},
"dependencies": {
"@ducanh2912/next-pwa": "latest",
"next": "13.4.1",
"next": "13.4.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"web-push": "3.6.1"
},
"devDependencies": {
"@types/node": "20.1.1",
"@types/react": "18.2.6",
"@types/node": "20.2.3",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"@types/web-push": "3.3.2",
"eslint": "8.40.0",
"eslint-config-next": "13.4.1",
"eslint": "8.41.0",
"eslint-config-next": "13.4.3",
"typescript": "5.0.4",
"webpack": "5.82.0"
"webpack": "5.84.0"
}
}
6 changes: 3 additions & 3 deletions examples/workboxless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
},
"dependencies": {
"@ducanh2912/next-sw": "latest",
"next": "13.4.1",
"next": "13.4.3",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "20.1.1",
"@types/react": "18.2.6",
"@types/node": "20.2.3",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"typescript": "5.0.4"
}
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@
"@changesets/cli": "2.26.1",
"@ducanh2912/next-pwa": "workspace:*",
"@ducanh2912/next-sw": "workspace:*",
"@types/node": "20.1.1",
"@types/node": "20.2.3",
"@types/shell-quote": "1.7.1",
"@typescript-eslint/eslint-plugin": "5.59.5",
"@typescript-eslint/parser": "5.59.5",
"@typescript-eslint/eslint-plugin": "5.59.7",
"@typescript-eslint/parser": "5.59.7",
"cross-env": "7.0.3",
"eslint": "8.40.0",
"eslint": "8.41.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-jsdoc": "44.0.2",
"eslint-plugin-jsdoc": "44.2.5",
"eslint-plugin-simple-import-sort": "10.0.0",
"fast-glob": "3.2.12",
"husky": "8.0.3",
"lint-staged": "13.2.2",
"npm-check-updates": "16.10.10",
"npm-check-updates": "16.10.12",
"prettier": "2.8.8",
"rimraf": "5.0.0",
"rimraf": "5.0.1",
"shell-quote": "1.8.1",
"tslib": "2.5.0",
"turbo": "1.9.3",
"typescript": "5.1.0-dev.20230509",
"webpack": "5.82.0"
"tslib": "2.5.2",
"turbo": "1.9.9",
"typescript": "5.2.0-dev.20230524",
"webpack": "5.84.0"
},
"packageManager": "[email protected]"
}
22 changes: 11 additions & 11 deletions packages/next-pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
"typecheck": "tsc"
},
"dependencies": {
"@swc/core": "1.3.57",
"@swc/core": "1.3.59",
"clean-webpack-plugin": "4.0.0",
"fast-glob": "3.2.12",
"semver": "7.5.0",
"semver": "7.5.1",
"swc-loader": "0.2.3",
"terser-webpack-plugin": "5.3.8",
"terser-webpack-plugin": "5.3.9",
"workbox-build": "6.5.4",
"workbox-core": "6.5.4",
"workbox-webpack-plugin": "6.5.4",
Expand All @@ -60,20 +60,20 @@
"devDependencies": {
"@rollup/plugin-json": "6.0.0",
"@rollup/plugin-node-resolve": "15.0.2",
"@rollup/plugin-terser": "0.4.1",
"@rollup/plugin-typescript": "11.1.0",
"@types/node": "20.1.1",
"@rollup/plugin-terser": "0.4.3",
"@rollup/plugin-typescript": "11.1.1",
"@types/node": "20.2.3",
"@types/semver": "7.5.0",
"chalk": "5.2.0",
"next": "13.4.1",
"next": "13.4.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"rollup": "3.21.5",
"rollup": "3.23.0",
"rollup-plugin-dts": "5.3.0",
"type-fest": "3.10.0",
"typescript": "5.1.0-dev.20230509",
"type-fest": "3.11.0",
"typescript": "5.2.0-dev.20230524",
"utils": "workspace:*",
"webpack": "5.82.0"
"webpack": "5.84.0"
},
"peerDependencies": {
"next": ">=9.1.0",
Expand Down
18 changes: 15 additions & 3 deletions packages/next-pwa/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ const defaultCache: RuntimeCaching[] = [
networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds
},
},
{
urlPattern: ({ request, url: { pathname }, sameOrigin }) =>
request.headers.get("RSC") === "1" &&
request.headers.get("Next-Router-Prefetch") === "1" &&
sameOrigin &&
!pathname.startsWith("/api/"),
handler: "NetworkFirst",
options: {
cacheName: "pages-rsc-prefetch",
expiration: {
maxEntries: 32,
maxAgeSeconds: 24 * 60 * 60, // 24 hours
},
},
},
{
urlPattern: ({ request, url: { pathname }, sameOrigin }) =>
request.headers.get("RSC") === "1" &&
Expand All @@ -169,9 +184,6 @@ const defaultCache: RuntimeCaching[] = [
maxEntries: 32,
maxAgeSeconds: 24 * 60 * 60, // 24 hours
},
// matchOptions: {
// ignoreVary: true,
// },
},
},
{
Expand Down
Loading

0 comments on commit 286f347

Please sign in to comment.