Commit 824fce58 by Wee

fix: fatal logic bug (v3.0.7)

parent e59feab9
...@@ -313,24 +313,24 @@ describe('A <Route>', () => { ...@@ -313,24 +313,24 @@ describe('A <Route>', () => {
expect(node.innerHTML).toContain(text) expect(node.innerHTML).toContain(text)
}) })
describe('that returns `undefined`', () => { // describe('that returns `undefined`', () => {
it('logs a warning to the console and renders nothing', () => { // it('logs a warning to the console and renders nothing', () => {
jest.spyOn(console, 'warn').mockImplementation(() => {}) // jest.spyOn(console, 'warn').mockImplementation(() => {})
renderStrict( // renderStrict(
<MemoryRouter initialEntries={['/']}> // <MemoryRouter initialEntries={['/']}>
<Route path="/" children={() => undefined} /> // <Route path="/" children={() => undefined} />
</MemoryRouter>, // </MemoryRouter>,
node // node
) // )
expect(node.innerHTML).toEqual('') // expect(node.innerHTML).toEqual('')
expect(console.warn).toHaveBeenCalledWith( // expect(console.warn).toHaveBeenCalledWith(
expect.stringContaining('You returned `undefined` from the `children` function') // expect.stringContaining('You returned `undefined` from the `children` function')
) // )
}) // })
}) // })
}) })
describe('that is an empty array (as in Preact)', () => { describe('that is an empty array (as in Preact)', () => {
......
{ {
"name": "react-live-route", "name": "react-live-route",
"version": "3.0.6", "version": "3.0.7",
"description": "A living route for react-router v4", "description": "A living route for react-router v4",
"repository": "fi3ework/react-live-route", "repository": "fi3ework/react-live-route",
"license": "MIT", "license": "MIT",
......
...@@ -209,56 +209,55 @@ class LiveRoute extends React.Component<PropsType, any> { ...@@ -209,56 +209,55 @@ class LiveRoute extends React.Component<PropsType, any> {
}) })
const matchAnyway = matchOfPath || matchOfLivePath const matchAnyway = matchOfPath || matchOfLivePath
// normal render // no render
if (
!matchAnyway ||
(matchAnyway &&
!matchOfPath &&
(this.liveState === LiveState.NORMAL_RENDER_ON_INIT || this.liveState === LiveState.NORMAL_RENDER_UNMATCHED))
) {
debugLog('--- not match ---')
this.liveState = LiveState.NORMAL_RENDER_UNMATCHED
return null
}
// normal render || hide render
if (matchOfPath) { if (matchOfPath) {
debugLog('--- normal match ---')
this.showRoute() this.showRoute()
this.restoreScrollPosition() this.restoreScrollPosition()
this.clearScroll() this.clearScroll()
// hide --> show // hide ➡️ show
if (this.liveState === LiveState.HIDE_RENDER) { if (this.liveState === LiveState.HIDE_RENDER) {
if (typeof onReappear === 'function') { if (typeof onReappear === 'function') {
onReappear(location!, matchAnyway, history, livePath, alwaysLive) onReappear(location!, matchAnyway, history, livePath, alwaysLive)
} }
} }
this.liveState = LiveState.NORMAL_RENDER_MATCHED this.liveState = LiveState.NORMAL_RENDER_MATCHED
} } else {
debugLog('--- hide match ---')
// hide render // force unmount
if (!matchOfPath && matchAnyway) { if (typeof forceUnmount === 'function' && forceUnmount(location, match, history, livePath, alwaysLive)) {
if (typeof forceUnmount === 'function') {
this.liveState = LiveState.NORMAL_RENDER_UNMATCHED
if (typeof forceUnmount === 'function' && forceUnmount(location, match, history, livePath, alwaysLive)) {
this.clearScroll()
this.clearDomData()
return null
}
}
// no-mount --> mount (alwaysLive)
if (this.liveState === LiveState.NORMAL_RENDER_ON_INIT && alwaysLive) {
this.liveState = LiveState.NORMAL_RENDER_UNMATCHED this.liveState = LiveState.NORMAL_RENDER_UNMATCHED
this.clearScroll()
this.clearDomData()
return null return null
} }
this.saveScrollPosition() // show ➡️ hide
this.hideRoute()
// show --> hide
if (this.liveState === LiveState.NORMAL_RENDER_MATCHED) { if (this.liveState === LiveState.NORMAL_RENDER_MATCHED) {
if (typeof onHide === 'function') { if (typeof onHide === 'function') {
onHide(location!, matchAnyway, history, livePath, alwaysLive) onHide(location!, matchAnyway, history, livePath, alwaysLive)
} }
this.saveScrollPosition()
this.hideRoute()
} }
this.liveState = LiveState.HIDE_RENDER this.liveState = LiveState.HIDE_RENDER
} }
// unmount // normal render
if (!matchAnyway) {
this.liveState = LiveState.NORMAL_RENDER_UNMATCHED
}
const props = { ...context, location, match: matchOfPath } const props = { ...context, location, match: matchOfPath }
// const props = { history, staticContext, location, match: matchAnyway } // const props = { history, staticContext, location, match: matchAnyway }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment