Skip to content

Commit

Permalink
Updated history js dependency to v5 resolves Github#1548
Browse files Browse the repository at this point in the history
  • Loading branch information
Sampo Kivistö committed Sep 12, 2021
1 parent 0abcc9f commit a95f57e
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 100 deletions.
16 changes: 8 additions & 8 deletions fixtures/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
"author": "",
"license": "MIT",
"dependencies": {
"@babel/core": "7.14.8",
"@babel/helper-replace-supers": "7.14.5",
"@babel/core": "7.15.5",
"@babel/helper-replace-supers": "7.15.4",
"@babel/plugin-proposal-class-properties": "7.14.5",
"@babel/plugin-proposal-decorators": "7.14.5",
"@babel/plugin-proposal-object-rest-spread": "7.14.7",
"@babel/preset-env": "7.14.8",
"@babel/plugin-proposal-decorators": "7.15.4",
"@babel/plugin-proposal-object-rest-spread": "7.15.6",
"@babel/preset-env": "7.15.6",
"babel-loader": "^8.2.2",
"jasmine-core": "^3.8.0",
"jasmine-core": "^3.9.0",
"karma": "^6.3.4",
"karma-chrome-launcher": "^3.1.0",
"karma-detect-browsers": "^2.3.3",
Expand All @@ -29,8 +29,8 @@
"karma-jasmine": "^4.0.1",
"karma-sauce-launcher": "^4.3.6",
"karma-webpack": "5.0.0",
"ts-loader": "^9.2.4",
"ts-loader": "^9.2.5",
"wd": "^1.14.0",
"webpack": "^5.47.1"
"webpack": "^5.52.1"
}
}
4 changes: 2 additions & 2 deletions fixtures/packaging/webpack-alias/dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "webpack-alias-dev-test",
"private": true,
"dependencies": {
"webpack": "^5.47.1",
"webpack-cli": "^4.7.2"
"webpack": "^5.52.1",
"webpack-cli": "^4.8.0"
},
"scripts": {
"build": "rm -f output.js && webpack --config config.js"
Expand Down
4 changes: 2 additions & 2 deletions fixtures/packaging/webpack-alias/prod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "webpack-alias-prod-test",
"private": true,
"dependencies": {
"webpack": "^5.47.1",
"webpack-cli": "^4.7.2"
"webpack": "^5.52.1",
"webpack-cli": "^4.8.0"
},
"scripts": {
"build": "rm -f output.js && webpack --config config.js"
Expand Down
4 changes: 2 additions & 2 deletions fixtures/packaging/webpack/dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "webpack-dev-test",
"private": true,
"dependencies": {
"webpack": "^5.47.1",
"webpack-cli": "^4.7.2"
"webpack": "^5.52.1",
"webpack-cli": "^4.8.0"
},
"scripts": {
"build": "rm -f output.js && webpack --config config.js"
Expand Down
4 changes: 2 additions & 2 deletions fixtures/packaging/webpack/prod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "webpack-prod-test",
"private": true,
"dependencies": {
"webpack": "^5.47.1",
"webpack-cli": "^4.7.2"
"webpack": "^5.52.1",
"webpack-cli": "^4.8.0"
},
"scripts": {
"build": "rm -f output.js && webpack --config config.js"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"d3-scale-chromatic": "^3.0.0",
"filesize": "^8.0.0",
"gzip-size": "^6.0.0",
"history": "^4.10.1",
"history": "^5.0.1",
"jest": "^27.1.1",
"jest-silent-reporter": "^0.5.0",
"jsdom": "^17.0.0",
Expand Down
50 changes: 10 additions & 40 deletions packages/inferno-router/__tests__/Link.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { render } from 'inferno';
import { HashRouter, Link, MemoryRouter } from 'inferno-router';
import { parsePath } from 'history';

describe('Link (jsx)', () => {
let node;
Expand All @@ -14,14 +15,9 @@ describe('Link (jsx)', () => {
});

it('accepts a location "to" prop', () => {
const location = {
pathname: '/the/path',
search: 'the=query',
hash: '#the-hash'
};
render(
<MemoryRouter>
<Link to={location}>link</Link>
<Link to={parsePath('/the/path?the=query#the-hash')}>link</Link>
</MemoryRouter>,
node
);
Expand Down Expand Up @@ -69,9 +65,9 @@ describe('A <Link> underneath a <HashRouter>', () => {
document.body.removeChild(node);
});

const createLinkNode = (hashType, to) => {
const createLinkNode = (to) => {
render(
<HashRouter hashType={hashType}>
<HashRouter>
<Link to={to} />
</HashRouter>,
node
Expand All @@ -80,39 +76,13 @@ describe('A <Link> underneath a <HashRouter>', () => {
return node.querySelector('a');
};

describe('with the "slash" hashType', () => {
it('has the correct href', () => {
const linkNode = createLinkNode('slash', '/foo');
expect(linkNode.getAttribute('href')).toEqual('#/foo');
});

it('has the correct href with a leading slash if it is missing', () => {
const linkNode = createLinkNode('slash', 'foo');
expect(linkNode.getAttribute('href')).toEqual('#/foo');
});
});

describe('with the "hashbang" hashType', () => {
it('has the correct href', () => {
const linkNode = createLinkNode('hashbang', '/foo');
expect(linkNode.getAttribute('href')).toEqual('#!/foo');
});

it('has the correct href with a leading slash if it is missing', () => {
const linkNode = createLinkNode('hashbang', 'foo');
expect(linkNode.getAttribute('href')).toEqual('#!/foo');
});
it('has the correct href', () => {
const linkNode = createLinkNode('/foo');
expect(linkNode.getAttribute('href')).toEqual('#/foo');
});

describe('with the "noslash" hashType', () => {
it('has the correct href', () => {
const linkNode = createLinkNode('noslash', 'foo');
expect(linkNode.getAttribute('href')).toEqual('#foo');
});

it('has the correct href and removes the leading slash', () => {
const linkNode = createLinkNode('noslash', '/foo');
expect(linkNode.getAttribute('href')).toEqual('#foo');
});
it('has the correct href #2', () => {
const linkNode = createLinkNode('foo');
expect(linkNode.getAttribute('href')).toEqual('#foo');
});
});
7 changes: 4 additions & 3 deletions packages/inferno-router/__tests__/Route.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render } from 'inferno';
import { MemoryRouter, Route, Router } from 'inferno-router';
import createMemoryHistory from 'history/createMemoryHistory';
import { createMemoryHistory } from 'history';

describe('A <Route>', () => {
it('renders at the root', () => {
Expand Down Expand Up @@ -91,7 +91,8 @@ describe('A <Route>', () => {
});

describe('A <Route> with dynamic segments in the path', () => {
it('decodes them', () => {
// https://github.com/remix-run/history/commit/78f016f6e5b49e2a23ec41799faf160dd68d6b6b
it('does not decode them', () => {
const node = document.createElement('div');
render(
<MemoryRouter initialEntries={['/a%20dynamic%20segment']}>
Expand All @@ -100,7 +101,7 @@ describe('A <Route> with dynamic segments in the path', () => {
node
);

expect(node.innerHTML).toContain('a dynamic segment');
expect(node.innerHTML).toContain('a%20dynamic%20segment');
});
});

Expand Down
14 changes: 7 additions & 7 deletions packages/inferno-router/__tests__/Router.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { render } from 'inferno';
import { Router } from 'inferno-router';
import createHistory from 'history/createMemoryHistory';
import { createMemoryHistory } from 'history';

describe('A <Router>', () => {
describe('with exactly one child', () => {
it('does not throw an error', () => {
const node = document.createElement('div');
expect(() => {
render(
<Router history={createHistory()}>
<Router history={createMemoryHistory()}>
<p>Bar</p>
</Router>,
node
Expand All @@ -21,7 +21,7 @@ describe('A <Router>', () => {
it('does not throw an error', () => {
const node = document.createElement('div');
expect(() => {
render(<Router history={createHistory()} />, node);
render(<Router history={createMemoryHistory()} />, node);
}).not.toThrow();
});
});
Expand All @@ -39,7 +39,7 @@ describe('A <Router>', () => {

it('puts history on context.history', () => {
const node = document.createElement('div');
const history = createHistory();
const history = createMemoryHistory();
render(
<Router history={history}>
<ContextChecker />
Expand All @@ -52,7 +52,7 @@ describe('A <Router>', () => {

it('sets context.router.route at the root', () => {
const node = document.createElement('div');
const history = createHistory({
const history = createMemoryHistory({
initialEntries: ['/']
});

Expand All @@ -72,7 +72,7 @@ describe('A <Router>', () => {

it('updates context.router.route upon navigation', () => {
const node = document.createElement('div');
const history = createHistory({
const history = createMemoryHistory({
initialEntries: ['/']
});

Expand All @@ -93,7 +93,7 @@ describe('A <Router>', () => {

it('does not contain context.router.staticContext by default', () => {
const node = document.createElement('div');
const history = createHistory({
const history = createMemoryHistory({
initialEntries: ['/']
});

Expand Down
6 changes: 3 additions & 3 deletions packages/inferno-router/__tests__/SwitchMount.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, render } from 'inferno';
import { Route, Router, Switch } from 'inferno-router';
import createHistory from 'history/createMemoryHistory';
import { createMemoryHistory } from 'history';

describe('A <Switch>', () => {
it('does not remount a <Route>', () => {
Expand All @@ -18,7 +18,7 @@ describe('A <Switch>', () => {
}
}

const history = createHistory({
const history = createMemoryHistory({
initialEntries: ['/one']
});

Expand Down Expand Up @@ -61,7 +61,7 @@ describe('A <Switch>', () => {
return <span>Okay</span>;
}

const history = createHistory({
const history = createMemoryHistory({
initialEntries: ['/one']
});

Expand Down
2 changes: 1 addition & 1 deletion packages/inferno-router/__tests__/mobx-router.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, render } from 'inferno';
import { inject, observer, Provider } from 'inferno-mobx';
import { Route, Router } from 'inferno-router';
import createMemoryHistory from 'history/createMemoryHistory';
import { createMemoryHistory } from 'history';
import { action, observable } from 'mobx';

describe('Github #1236', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/inferno-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
"directory": "packages/inferno-router"
},
"peerDependencies": {
"history": "^4.10.1",
"history": "^5.0.1",
"path-to-regexp-es6": "1.7.0"
},
"dependencies": {
"history": "^4.10.1",
"history": "^5.0.1",
"hoist-non-inferno-statics": "^1.1.3",
"inferno": "7.4.10",
"path-to-regexp-es6": "1.7.0"
Expand Down
9 changes: 3 additions & 6 deletions packages/inferno-router/src/HashRouter.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { Component, createComponentVNode, VNode } from 'inferno';
import { Component, createComponentVNode, InfernoNode, VNode } from 'inferno';
import { VNodeFlags } from 'inferno-vnode-flags';
import { createHashHistory } from 'history';
import { Router } from './Router';
import { warning } from './utils';

export interface IHashRouterProps {
basename?: string;
getUserConfirmation?: () => {};
hashType?: string;
children: Component<any, any>[] | JSX.Element;
children: InfernoNode;
}

export class HashRouter extends Component<IHashRouterProps, any> {
public history;

constructor(props?: any, context?: any) {
super(props, context);
this.history = createHashHistory(props);
this.history = createHashHistory();
}

public render(): VNode {
Expand Down
5 changes: 3 additions & 2 deletions packages/inferno-router/src/Link.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createVNode, InfernoMouseEvent, linkEvent, VNode } from 'inferno';
import { ChildFlags, VNodeFlags } from 'inferno-vnode-flags';
import { invariant } from './utils';
import { combineFrom } from 'inferno-shared';
import { combineFrom, isString } from 'inferno-shared';
import { parsePath } from 'history';
import type { Location } from 'history';

const isModifiedEvent = (event: InfernoMouseEvent<any>): boolean => Boolean(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
Expand Down Expand Up @@ -47,7 +48,7 @@ export function Link(props: ILinkProps & LinkHTMLAttributes<HTMLLinkElement>, co
const { replace, children, className, to = '', innerRef, ...rest } = props;
invariant(context.router, 'You should not use <Link> outside a <Router>');

const href = context.router.history.createHref(typeof to === 'string' ? { pathname: to } : to);
const href = context.router.history.createHref(isString(to) ? parsePath(to) : to);
const newProps: any = combineFrom(rest, null);

newProps.href = href;
Expand Down
21 changes: 15 additions & 6 deletions packages/inferno-router/src/Redirect.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { Component } from 'inferno';
import { createLocation, locationsAreEqual } from 'history';
import { invariant } from './utils';
import { parsePath, Location, Path } from 'history';
import { combinePath, invariant } from './utils';
import { isString } from 'inferno-shared';

export interface RedirectProps {
from?: string;
to: string;
to: string | Location;
exact?: any;
push?: boolean;
}

function getLocationTarget(to): Partial<Path> {
if (!isString(to)) {
to = combinePath(to);
}

return parsePath(to);
}

export class Redirect extends Component<RedirectProps, any> {
public isStatic() {
return this.context.router && this.context.router.staticContext;
Expand All @@ -29,10 +38,10 @@ export class Redirect extends Component<RedirectProps, any> {
}

public componentDidUpdate(prevProps) {
const prevTo = createLocation(prevProps.to);
const nextTo = createLocation(this.props.to);
const prevTo = getLocationTarget(prevProps.to);
const nextTo = getLocationTarget(this.props.to);

if (locationsAreEqual(prevTo, nextTo)) {
if (prevTo.pathname === nextTo.pathname && prevTo.search === nextTo.search) {
// tslint:disable-next-line:no-console
console.error(`You tried to redirect to the same route you're currently on: "${nextTo.pathname}${nextTo.search}"`);
return;
Expand Down
Loading

0 comments on commit a95f57e

Please sign in to comment.