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

fix: properly handle routeChangeError #80

Merged
merged 5 commits into from
Aug 16, 2022
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
22 changes: 22 additions & 0 deletions .github/problemMatchers/eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"problemMatcher": [
{
"owner": "eslint-stylish",
"pattern": [
{
"regexp": "^([^\\s].*)$",
"file": 1
},
{
"regexp": "^\\s+(\\d+):(\\d+)\\s+(error|warning|info)\\s+(.*)\\s\\s+(.*)$",
"line": 1,
"column": 2,
"severity": 3,
"message": 4,
"code": 5,
"loop": true
}
]
}
]
}
17 changes: 17 additions & 0 deletions .github/problemMatchers/tsc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "tsc",
"pattern": [
{
"regexp": "^(?:\\s+\\d+\\>)?([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\)\\s*:\\s+(error|warning|info)\\s+(\\w{1,2}\\d+)\\s*:\\s*(.*)$",
"file": 1,
"location": 2,
"severity": 3,
"code": 4,
"message": 5
}
]
}
]
}
30 changes: 0 additions & 30 deletions .github/workflows/build.yml

This file was deleted.

46 changes: 46 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Continuous Integration

on:
push:
branches:
- master
pull_request:

jobs:
Linting:
name: Linting
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
- name: Add problem matcher
run: echo "::add-matcher::.github/problemMatchers/eslint.json"
- name: Use Node.js v16
uses: actions/setup-node@2fddd8803e2f5c9604345a0b591c3020ee971a93 # tag=v3
with:
node-version: 16
cache: yarn
registry-url: https://registry.npmjs.org/
- name: Install Dependencies
run: yarn --frozen-lockfile
- name: Run ESLint
run: yarn lint --fix=false

Building:
name: Compile source code
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3
- name: Add problem matcher
run: echo "::add-matcher::.github/problemMatchers/tsc.json"
- name: Use Node.js v16
uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # tag=v3
with:
node-version: 16
cache: yarn
registry-url: https://registry.npmjs.org/
- name: Install Dependencies
run: yarn --frozen-lockfile
- name: Typecheck And Build Code
run: yarn typecheck && yarn build
30 changes: 0 additions & 30 deletions .github/workflows/lint.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .npmignore

This file was deleted.

6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 120,
"singleQuote": true,
"quoteProps": "as-needed",
"endOfLine": "lf"
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelogs

## v0.0.15

- Properly handle `routeChangeError` event

## v0.0.14

### Added
Expand Down
34 changes: 21 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"name": "nextjs-progressbar",
"version": "0.0.14",
"version": "0.0.15",
"description": "Nprogress component for Next.js app.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsup & tsc -p tsconfig.json",
"prepublish": "npm run build",
"lint": "eslint src/"
"build": "tsup",
"prepack": "npm run build",
"lint": "eslint --fix --cache src/",
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
"typecheck": "tsc -p tsconfig.json"
},
"repository": {
"type": "git",
Expand All @@ -25,24 +27,30 @@
"url": "https://github.com/apal21/nextjs-progressbar/issues"
},
"homepage": "https://github.com/apal21/nextjs-progressbar#readme",
"files": [
"dist/**/*.js*",
"dist/**/*.mjs*",
"dist/**/*.d*"
],
"peerDependencies": {
"next": ">= 6.0.0",
"react": ">= 16.0.0"
},
"dependencies": {
"@types/nprogress": "^0.2.0",
"nprogress": "^0.2.0",
"prop-types": "^15.7.2"
},
"devDependencies": {
"@types/node": "^17.0.21",
"@types/nprogress": "^0.2.0",
"@types/react": "^17.0.37",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"eslint": "^8.5.0",
"next": "^12.0.7",
"react": "^17.0.2",
"tsup": "^5.11.13",
"typescript": "^4.5.4"
"@types/react": "^18.0.17",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"eslint": "^8.21.0",
"next": "^12.2.4",
"prettier": "^2.7.1",
"react": "^18.2.0",
"tsup": "^6.2.1",
"typescript": "^4.7.4"
}
}
21 changes: 19 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ export default function NextNProgress({
}
Router.events.on('routeChangeStart', routeChangeStart);
Router.events.on('routeChangeComplete', routeChangeEnd);
Router.events.on('routeChangeError', routeChangeEnd);
Router.events.on('routeChangeError', routeChangeError);
return () => {
Router.events.off('routeChangeStart', routeChangeStart);
Router.events.off('routeChangeComplete', routeChangeEnd);
Router.events.off('routeChangeError', routeChangeEnd);
Router.events.off('routeChangeError', routeChangeError);
};
}, []);

Expand Down Expand Up @@ -100,6 +100,23 @@ export default function NextNProgress({
}
};

const routeChangeError = (
_err: Error,
_url: string,
{
shallow,
}: {
shallow: boolean;
}
) => {
if (!shallow || showOnShallow) {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
NProgress.done(true);
}, stopDelayMs);
}
};

return (
<style nonce={nonce}>{`
#nprogress {
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"moduleResolution": "node",
"lib": ["es2021"],
"skipLibCheck": true,
"declaration": true,
"emitDeclarationOnly": true,
"noEmit": true,
"outDir": "dist"
},
"files": ["src/index.tsx"]
Expand Down
2 changes: 1 addition & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Options } from 'tsup';
export const tsup: Options = {
target: 'esnext',
clean: true,
dts: false,
dts: true,
entry: ['src/index.tsx'],
keepNames: true,
minify: true,
Expand Down
Loading