Commit 824fce58 by Wee

fix: fatal logic bug (v3.0.7)

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