forked from shadowwalker/next-pwa
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): fixed invalid precache manifest and scope with
basePath
[bump]
- Loading branch information
Showing
9 changed files
with
105 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"@ducanh2912/next-pwa": patch | ||
--- | ||
|
||
fix(core): fixed invalid precache manifest and scope with `basePath` | ||
|
||
- A fast backport of https://github.com/serwist/serwist/pull/56. | ||
- This is caused by "/\_next/../public" in modifyURLPrefix not being matched when basePath is set, since the URL is actually "${basePath}/\_next/../public/\*\*/\*". We now use `manifestTransforms` instead of `modifyURLPrefix`. | ||
- Also, with the refactor to using a context, we mistakenly changed `scope` from "${scope}" (suffixed with / if originally not) to "${basePath}/${scope}". This reverts that change. Sorry for the inconvenience! |
Binary file not shown.
8 changes: 8 additions & 0 deletions
8
packages/next-pwa/__tests__/integration/base-path/app/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const RootLayout = ({ children }: { children: React.ReactNode }) => ( | ||
<html lang="en"> | ||
<head /> | ||
<body>{children}</body> | ||
</html> | ||
); | ||
|
||
export default RootLayout; |
10 changes: 10 additions & 0 deletions
10
packages/next-pwa/__tests__/integration/base-path/app/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Image from "next/image"; | ||
|
||
const Page = () => ( | ||
<main> | ||
<p id="welcome-text">This is a Next.js PWA!</p> | ||
<Image src="/next.svg" alt="Next.js Logo" width={180} height={37} priority /> | ||
</main> | ||
); | ||
|
||
export default Page; |
26 changes: 26 additions & 0 deletions
26
packages/next-pwa/__tests__/integration/base-path/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { createDescribe } from "../../test-utils/index.ts"; | ||
|
||
createDescribe("integration basePath", { sourceDir: __dirname, skipInstall: false }, ({ next, testMode }) => { | ||
it("should render", async () => { | ||
const $ = await next.render("/next-pwa"); | ||
expect($("#welcome-text").text()).toBe("This is a Next.js PWA!"); | ||
}); | ||
|
||
it("should fetch image", async () => { | ||
const image = await next.fetch("/next-pwa/next.svg"); | ||
expect(image.status).toBe(200); | ||
const favicon = await next.fetch("/next-pwa/favicon.ico"); | ||
expect(favicon.status).toBe(200); | ||
}); | ||
|
||
it("should be able to fetch service worker", async () => { | ||
const sw = await next.fetch("/next-pwa/sw.js"); | ||
expect(sw.status).toBe(200); | ||
expect(sw.headers.get("Content-Type")?.includes("application/javascript")).toBe(true); | ||
const swContent = await sw.text(); | ||
if (testMode === "start") { | ||
expect(/url:\"\/next-pwa\/swe-worker-(.*?).js\"/.test(swContent)).toBe(true); | ||
expect(/url:\"\/next-pwa\/_next\/..\/public\/swe-worker-(.*?).js\"/.test(swContent)).toBe(false); | ||
} | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
packages/next-pwa/__tests__/integration/base-path/next.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// @ts-check | ||
import withPWAInit from "@ducanh2912/next-pwa"; | ||
|
||
const withPWA = withPWAInit({ | ||
dest: "public", | ||
cacheOnFrontEndNav: true, | ||
}); | ||
|
||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
basePath: "/next-pwa", | ||
}; | ||
|
||
export default withPWA(nextConfig); |
1 change: 1 addition & 0 deletions
1
packages/next-pwa/__tests__/integration/base-path/public/next.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions
29
packages/next-pwa/__tests__/integration/base-path/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowImportingTsExtensions": true, | ||
"target": "es5", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"incremental": true, | ||
"plugins": [ | ||
{ | ||
"name": "next" | ||
} | ||
], | ||
"paths": { | ||
"@/*": ["./src/*"] | ||
} | ||
}, | ||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], | ||
"exclude": ["node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters