Option to skip first render
See original GitHub issueI have a situation with a client-side router (a fork of React Router v3) which does an initial empty render to match routes - returning null
- then a second render that actually renders the app. I’m also server-side rendering - so the DOM is already populated - and when the client renders the first time, there’s a flash of empty page caused by route matching, then the app is rendered again.
This is not an issue with Preact, but the only solution I found was to make Preact.render ignore the first render. It required only very minor changes: for render()
to pass an initial context to diff()
…
export function render(vnode, parent, merge, context = {}) {
return diff(merge, vnode, context, false, parent, false)
}
Then for diff to ignore rendering if specified:
export function diff(dom, vnode, context, mountAll, parent, componentRoot) {
if (!vnode && context && context.ignoreFirstRender) {
delete context.ignoreFirstRender
return dom
}
...
Would you consider adding such an option to Preact? I know the real solution would be to rewrite the route matching algorithm to not require an initial empty render, but that seemed to be much more complex.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
Async rendering is something that’s on our minds, but will take a bit of time to get it working. Let’s continue the discussion in #862 or #526
Yup. It would also enable awesome stuff like waiting to update components until there are some CPU cycles free.