SlideShare a Scribd company logo
ReactJS
Re-rendering pages in the age of the mutable DOM
React re-renders entire component
whenever data changes
• 80s/90s — user input caused re-render of entire
web page. Why is this best?
• Immutable vs Mutable — mutations can cause
complexity to a point where an app is no longer
maintainable
“React components are idempotent functions.
They describe your UI at any point in time, just
like a server-rendered application.”
What does React do about
Mutable vs Immutable state?
• React isolates mutable state as much as possible.
• Re-rendering on every change makes things simple -
data is guaranteed to be up-to-date
• This is w/out magical data-binding, w/out model dirty
checking, and w/out explicit DOM operations
• Extra note: Why is dirty checking bad? It’s expensive
and as your application grows in complexity, it can
cause your code to get out of hand quickly
Everything is
declarative!
But how can you re-render every
time data changes?
Isn’t this too expensive?
… Enter the Virtual
DOM
What is the v-DOM and how
does it work?
• The v-DOM is a virtualized representation of the
DOM at different points in time (before and after
state change)
• This virtualization is made up of lightweight
JavaScript objects that represent the DOM tree.
As such - it is inexpensive to store in memory and
allows the diffing algorithm to execute in
milliseconds
On every update…
• React builds a new v-DOM subtree
• diffs it with the old one
• computes the minimal set of DOM mutations and
puts them in queue
• and batch executes all updates
It does this in
milliseconds
• React is fast because it computes minimal DOM
operations — the DOM is slow, JavaScript is
actually very, very fast
• React batches read/writes for optimal
performance automatically. It does this through
use of the v-DOM which is inherently faster than
the actual DOM.
Some other points of interest
• Automatic top-level event delegation with cross-
browser HTML5 events
• React also has a virtual event system in addition
to the v-DOM system
What else matters?
Web crawlers!
• One of the big drawbacks to single-page
applications that rely on user input is that web
crawlers can’t index them the same way they can
static pages
• React can generate a static HTML page and send
it down to the client, and then when render
component is called, it looks at the DOM - checks
with what was rendered on server... fast initial page
load experience and Google web-bots can crawl
What does that mean…
the long paragraph there?
“React can generate a static HTML page and
send it down to the client, and then when render
component is called, it looks at the DOM -
checks with what was rendered on server... fast
initial page load experience and Google web-
bots can crawl.”
What this means…
• You can generate a static html page and send it
down — something that can be crawled and
indexed
• Then, when JS boots up, it will replace DOM
elements as needed to boot up the UI
• Resulting in an indexable page that is fully built
on JavaScript
Let’s pause for a minute to note
some key takeaways so far
• Build components, not templates
• Re-render, don’t mutate
• V-DOM is simple and fast
So where does Flux come
in? … also, Relay is
coming soon
As you build apps on React,
you will remove models
• In most MV* JS frameworks, model is just a JS object
that allows you to know when something changes —
when data changes (enter two-way data-binding)
• Example:
• You have a model with Title and Subtitle. When something changes you manually
wire up the views to have a node change when the Title changes.
• You change the inner text on some node when the Title changes
• You have to wire this up yourself completely — in Backbone, you have to
wire both ways. In some other frameworks, you only have to wire one way,
but this is still a lot of code.
How is React different
in this example?
With React…
• You trigger a state change.
• Re-render happens.
• Diff happens in background automatically.
• View updates without any flashing in the DOM and
it happens very, very quickly.
• This shortens the amount of code you have to
write.
React can be most powerful
without models
• This does not mean you don’t have data structure
• You use the Flux design pattern (or coming soon,
the Relay framework)
• This is where stores come in…
What is a Store?
Everything’s in Flux
• Centralized stores represent UI components
• The store is your source of truth for the data of
your application
• When you ask a store for data, if it doesn’t have
it, it fetches it and invokes your callback after it
gets it
This centralizes validation
and update logic in one
place.
Think about it.. mutation
all over the place is not
ideal.
ReactJS - Re-rendering pages in the age of the mutable DOM
More on Relay when it
becomes available to the
public as open-source
Ad

More Related Content

What's hot (20)

React JS & Functional Programming Principles
React JS & Functional Programming PrinciplesReact JS & Functional Programming Principles
React JS & Functional Programming Principles
Andrii Lundiak
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to React
Rob Quick
 
reactJS
reactJSreactJS
reactJS
Syam Santhosh
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace IT
namespaceit
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
L&T Technology Services Limited
 
ReactJS
ReactJSReactJS
ReactJS
Hiten Pratap Singh
 
Reactjs
ReactjsReactjs
Reactjs
Mallikarjuna G D
 
React Hooks
React HooksReact Hooks
React Hooks
Joao Marins
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
Ritesh Mehrotra
 
All about Context API
All about Context APIAll about Context API
All about Context API
Souvik Basu
 
React and redux
React and reduxReact and redux
React and redux
Mystic Coders, LLC
 
Introduction to JWT and How to integrate with Spring Security
Introduction to JWT and How to integrate with Spring SecurityIntroduction to JWT and How to integrate with Spring Security
Introduction to JWT and How to integrate with Spring Security
Bruno Henrique Rother
 
React state
React  stateReact  state
React state
Ducat
 
React new features and intro to Hooks
React new features and intro to HooksReact new features and intro to Hooks
React new features and intro to Hooks
Soluto
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
Tariqul islam
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
Mohammed Fazuluddin
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
Nikolaus Graf
 
Intro to React
Intro to ReactIntro to React
Intro to React
Eric Westfall
 
React hooks
React hooksReact hooks
React hooks
Assaf Gannon
 
React workshop
React workshopReact workshop
React workshop
Imran Sayed
 
React JS & Functional Programming Principles
React JS & Functional Programming PrinciplesReact JS & Functional Programming Principles
React JS & Functional Programming Principles
Andrii Lundiak
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to React
Rob Quick
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace IT
namespaceit
 
All about Context API
All about Context APIAll about Context API
All about Context API
Souvik Basu
 
Introduction to JWT and How to integrate with Spring Security
Introduction to JWT and How to integrate with Spring SecurityIntroduction to JWT and How to integrate with Spring Security
Introduction to JWT and How to integrate with Spring Security
Bruno Henrique Rother
 
React state
React  stateReact  state
React state
Ducat
 
React new features and intro to Hooks
React new features and intro to HooksReact new features and intro to Hooks
React new features and intro to Hooks
Soluto
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
Tariqul islam
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
Mohammed Fazuluddin
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
Nikolaus Graf
 

Similar to ReactJS - Re-rendering pages in the age of the mutable DOM (20)

React js
React jsReact js
React js
Nikhil Karkra
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016
Marco Breveglieri
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - Talk
Matthias Noback
 
Benefits of developing single page web applications using angular js
Benefits of developing single page web applications using angular jsBenefits of developing single page web applications using angular js
Benefits of developing single page web applications using angular js
Harbinger Systems - HRTech Builder of Choice
 
Meteor Revolution: From DDP to Blaze Reactive Rendering
Meteor Revolution: From DDP to Blaze Reactive Rendering Meteor Revolution: From DDP to Blaze Reactive Rendering
Meteor Revolution: From DDP to Blaze Reactive Rendering
Massimo Sgrelli
 
Reactjs notes.pptx for web development- tutorial and theory
Reactjs  notes.pptx for web development- tutorial and theoryReactjs  notes.pptx for web development- tutorial and theory
Reactjs notes.pptx for web development- tutorial and theory
jobinThomas54
 
Learning React - I
Learning React - ILearning React - I
Learning React - I
Mitch Chen
 
Introduction to react native with redux
Introduction to react native with reduxIntroduction to react native with redux
Introduction to react native with redux
Mike Melusky
 
React.js at Cortex
React.js at CortexReact.js at Cortex
React.js at Cortex
Geoff Harcourt
 
Intro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NETIntro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NET
Alan Hecht
 
mearn-stackjdksjdsfjdkofkdokodkojdj.pptx
mearn-stackjdksjdsfjdkofkdokodkojdj.pptxmearn-stackjdksjdsfjdkofkdokodkojdj.pptx
mearn-stackjdksjdsfjdkofkdokodkojdj.pptx
aravym456
 
Meteor + React
Meteor + ReactMeteor + React
Meteor + React
Taggart Bowen-Gaddy
 
What is virtual dom in react js
What is virtual dom in react jsWhat is virtual dom in react js
What is virtual dom in react js
BOSC Tech Labs
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!
Jeremy Likness
 
Advanced web application architecture Way2Web
Advanced web application architecture Way2WebAdvanced web application architecture Way2Web
Advanced web application architecture Way2Web
Matthias Noback
 
React introduction
React introductionReact introduction
React introduction
Kashyap Parmar
 
ReactJS Code Impact
ReactJS Code ImpactReactJS Code Impact
ReactJS Code Impact
Raymond McDermott
 
React DOM/Virtual DOM
React DOM/Virtual DOMReact DOM/Virtual DOM
React DOM/Virtual DOM
RajasreePothula3
 
React + Mobile
React + MobileReact + Mobile
React + Mobile
antriss
 
Robust web apps with React.js
Robust web apps with React.jsRobust web apps with React.js
Robust web apps with React.js
Max Klymyshyn
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016
Marco Breveglieri
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - Talk
Matthias Noback
 
Meteor Revolution: From DDP to Blaze Reactive Rendering
Meteor Revolution: From DDP to Blaze Reactive Rendering Meteor Revolution: From DDP to Blaze Reactive Rendering
Meteor Revolution: From DDP to Blaze Reactive Rendering
Massimo Sgrelli
 
Reactjs notes.pptx for web development- tutorial and theory
Reactjs  notes.pptx for web development- tutorial and theoryReactjs  notes.pptx for web development- tutorial and theory
Reactjs notes.pptx for web development- tutorial and theory
jobinThomas54
 
Learning React - I
Learning React - ILearning React - I
Learning React - I
Mitch Chen
 
Introduction to react native with redux
Introduction to react native with reduxIntroduction to react native with redux
Introduction to react native with redux
Mike Melusky
 
Intro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NETIntro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NET
Alan Hecht
 
mearn-stackjdksjdsfjdkofkdokodkojdj.pptx
mearn-stackjdksjdsfjdkofkdokodkojdj.pptxmearn-stackjdksjdsfjdkofkdokodkojdj.pptx
mearn-stackjdksjdsfjdkofkdokodkojdj.pptx
aravym456
 
What is virtual dom in react js
What is virtual dom in react jsWhat is virtual dom in react js
What is virtual dom in react js
BOSC Tech Labs
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!
Jeremy Likness
 
Advanced web application architecture Way2Web
Advanced web application architecture Way2WebAdvanced web application architecture Way2Web
Advanced web application architecture Way2Web
Matthias Noback
 
React + Mobile
React + MobileReact + Mobile
React + Mobile
antriss
 
Robust web apps with React.js
Robust web apps with React.jsRobust web apps with React.js
Robust web apps with React.js
Max Klymyshyn
 
Ad

Recently uploaded (20)

Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Ad

ReactJS - Re-rendering pages in the age of the mutable DOM

  • 1. ReactJS Re-rendering pages in the age of the mutable DOM
  • 2. React re-renders entire component whenever data changes • 80s/90s — user input caused re-render of entire web page. Why is this best? • Immutable vs Mutable — mutations can cause complexity to a point where an app is no longer maintainable
  • 3. “React components are idempotent functions. They describe your UI at any point in time, just like a server-rendered application.”
  • 4. What does React do about Mutable vs Immutable state? • React isolates mutable state as much as possible. • Re-rendering on every change makes things simple - data is guaranteed to be up-to-date • This is w/out magical data-binding, w/out model dirty checking, and w/out explicit DOM operations • Extra note: Why is dirty checking bad? It’s expensive and as your application grows in complexity, it can cause your code to get out of hand quickly
  • 6. But how can you re-render every time data changes? Isn’t this too expensive?
  • 7. … Enter the Virtual DOM
  • 8. What is the v-DOM and how does it work? • The v-DOM is a virtualized representation of the DOM at different points in time (before and after state change) • This virtualization is made up of lightweight JavaScript objects that represent the DOM tree. As such - it is inexpensive to store in memory and allows the diffing algorithm to execute in milliseconds
  • 9. On every update… • React builds a new v-DOM subtree • diffs it with the old one • computes the minimal set of DOM mutations and puts them in queue • and batch executes all updates
  • 10. It does this in milliseconds
  • 11. • React is fast because it computes minimal DOM operations — the DOM is slow, JavaScript is actually very, very fast • React batches read/writes for optimal performance automatically. It does this through use of the v-DOM which is inherently faster than the actual DOM.
  • 12. Some other points of interest • Automatic top-level event delegation with cross- browser HTML5 events • React also has a virtual event system in addition to the v-DOM system
  • 14. Web crawlers! • One of the big drawbacks to single-page applications that rely on user input is that web crawlers can’t index them the same way they can static pages • React can generate a static HTML page and send it down to the client, and then when render component is called, it looks at the DOM - checks with what was rendered on server... fast initial page load experience and Google web-bots can crawl
  • 15. What does that mean… the long paragraph there?
  • 16. “React can generate a static HTML page and send it down to the client, and then when render component is called, it looks at the DOM - checks with what was rendered on server... fast initial page load experience and Google web- bots can crawl.”
  • 17. What this means… • You can generate a static html page and send it down — something that can be crawled and indexed • Then, when JS boots up, it will replace DOM elements as needed to boot up the UI • Resulting in an indexable page that is fully built on JavaScript
  • 18. Let’s pause for a minute to note some key takeaways so far • Build components, not templates • Re-render, don’t mutate • V-DOM is simple and fast
  • 19. So where does Flux come in? … also, Relay is coming soon
  • 20. As you build apps on React, you will remove models • In most MV* JS frameworks, model is just a JS object that allows you to know when something changes — when data changes (enter two-way data-binding) • Example: • You have a model with Title and Subtitle. When something changes you manually wire up the views to have a node change when the Title changes. • You change the inner text on some node when the Title changes • You have to wire this up yourself completely — in Backbone, you have to wire both ways. In some other frameworks, you only have to wire one way, but this is still a lot of code.
  • 21. How is React different in this example?
  • 22. With React… • You trigger a state change. • Re-render happens. • Diff happens in background automatically. • View updates without any flashing in the DOM and it happens very, very quickly. • This shortens the amount of code you have to write.
  • 23. React can be most powerful without models • This does not mean you don’t have data structure • You use the Flux design pattern (or coming soon, the Relay framework) • This is where stores come in…
  • 24. What is a Store?
  • 25. Everything’s in Flux • Centralized stores represent UI components • The store is your source of truth for the data of your application • When you ask a store for data, if it doesn’t have it, it fetches it and invokes your callback after it gets it
  • 26. This centralizes validation and update logic in one place.
  • 27. Think about it.. mutation all over the place is not ideal.
  • 29. More on Relay when it becomes available to the public as open-source