A Journey
through a slow
React application
⛵ ❤ _
PAVITHRA KODMAD
@PKodmad
ASSUMPTIONS
❤
@PKodmad
ASSUMPTIONS
This is Jira
@PKodmad
issue view
https://www.page1.com/browse/issue-1
My Project My Project/issue-1
Burning task, please complete!
Customer is really pissed about this, find a way to fix this. 

There’s really no legit way to reproduce this yet, but you gotta

try more.
ASSIGNEE

PK
LAUNCH DATE

29/02/2019
ESTIMATE

200
BOARD
BACKLOG
ISSUES
REPORTS
ASSUMPTIONS
@PKodmad
Backlog
https://www.page1.com/projectkey/backlog
My Project
BOARD
BACKLOG
ISSUES
REPORTS
BACKLOG
ISSUE 1 - Fix this first
ISSUE 2 - Fix this next
ISSUE 3 - Fix this later
ISSUE 4 - Fix this never
ASSUMPTIONS
@PKodmad
Board
https://www.page1.com/projectkey/board
My Project
BOARD
BACKLOG
ISSUES
REPORTS
BOARD
TO DO
Fix this never
Issue - 4
Fix this if possible
Issue - 3
WIP
Fix this next
Issue - 2
DONE
Fix this first
Issue - 1
ASSUMPTIONS
@PKodmad
ASSUMPTIONS
Client Side Rendering = React.render()
issue view
https://www.page1.com/browse/issue-1
My Project My Project/issue-1
Burning task, please complete!
Customer is really pissed about this, find a way to fix
this. There’s really no legit way to reproduce this yet,
but you gotta try more.
ASSIGNEE

PK
LAUNCH DATE

29/02/2019
ESTIMATE

200
BOARD
BACKLOG
ISSUES
REPORTS
Fix fast! Can’t wait
COMMENTS
@PKodmad
ASSUMPTIONS
Server Side Rendering = React.renderToString()
issue view
https://www.page1.com/browse/issue-1
My Project My Project/issue-1
Burning task, please complete!
Customer is really pissed about this, find a way to fix
this. There’s really no legit way to reproduce this yet,
but you gotta try more.
ASSIGNEE

PK
LAUNCH DATE

29/02/2019
ESTIMATE

200
BOARD
BACKLOG
ISSUES
REPORTS
Fix fast! Can’t wait
COMMENTS
@PKodmad
ASSUMPTIONS
SPA - Single Page Application
@PKodmad
ASSUMPTIONS
TTR - Time to render
TTI - Time to Interactive
@PKodmad
REACT PERFORMANCE
@PKodmad
Do you really have a problem with
performance though?
@PKodmad
IN THREE ACTS
@PKodmad
The data fetching duality
ACT 1
@PKodmad
@PKodmad
DATA IN SSR
data = fetch()
store = createStore()
state = store.getState()
window.SSR_DATA = state
@PKodmad
DATA IN SPA
initialState = window.SSR_DATA
store = createStore(initialState)
@PKodmad
Router
@PKodmad
❌
<Router>

{children}

<Router/>
<PrefetchCacheProvider>
<PrefetchCacheProvider/>
Powered by react context
@PKodmad
{ (data, loading) =>
<PartofApp data={data} />
}
<PrefetchQuery resolve={}>
<PrefetchQuery/>
Only to be used in 

case of SSR
@PKodmad
Route?
@PKodmad
Double rendering strategy
👍 for reuse
🤒 for performance
@PKodmad
treewalk +TTR = fetch + render
@PKodmad
treewalk +TTR = fetch + render
@PKodmad
Thanks react-router docs.
@PKodmad
@PKodmad
<SuspenseForSSR />
PREFERRED
SOLUTION
The loading page congruence
ACT 2
@PKodmad
@PKodmad
SSR HTML ❌= Client HTML
1. Analytics HOC

2. Logging Infra

3. In product help
@PKodmad
React.hydrate(<App />)
❌
@PKodmad
issue view
https://www.page1.com/browse/issue-1
My Project My Project/issue-1
Burning task, please complete!
Customer is really pissed about this, find a way to fix this. 

There’s really no legit way to reproduce this yet, but you gotta

try more.
ASSIGNEE

PK
LAUNCH DATE

29/02/2019
ESTIMATE

200
BOARD
BACKLOG
ISSUES
REPORTS
If you intentionally need to render
something different on the server and
the client, you can do a two-pass
rendering.
@PKodmad
Double render?
https://reactjs.org/docs/react-dom.html#hydrate
@PKodmad
const html = saveSSRHTML()
React.render(<App />)
if (loading) { }if (loading) { <div dangerouslySetInnerHTML={html} /> }
@PKodmad
PREFERRED
SOLUTION
🤷
The state management formulation
ACT 3
@PKodmad
@PKodmad
@PKodmad
https://github.com/facebook/react/issues/13739
@PKodmad
https://github.com/reduxjs/react-redux/issues/1177
@PKodmad
https://github.com/facebook/react/issues/14110
@PKodmad
react-sweet-state
@albertogasparin
https://github.com/atlassian/react-sweet-state/blob/
b155c6b6eab13df306d6413dee343b0bd8d99846/src/context.js
@PKodmad
Scaling perf issues
Lack of selectors
Debugging workflow
Provider hell
@PKodmad
@PKodmad
PREFERRED
SOLUTION
Honorable mentions
• React.memo()
• Lighter SSR components
• Page Ready indicator
@PKodmad
Thanks for the dev tools
@PKodmad
@PKodmad
“All good things happen just outside of your comfort zone”
@PKodmad
If you send some props
Its so lovely..
If you set the state
Its okay..
If you send some props
Its so lovely..
If you set the state
Its okay..
@PKodmad
You sync the DOM
By next tick tick tick
By next tick tick tick
Reeeact.. 😂
@PKodmad
Million providers with no owners
Million memoized functions I write
Million components I create
Million renders squeeze my thread
Time for some hooks..
Tick tick tick
@PKodmad
@PKodmad
Thank you for all the ❤

A journey through a slow react app.