<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ben Edelstein on Medium]]></title>
        <description><![CDATA[Stories by Ben Edelstein on Medium]]></description>
        <link>https://medium.com/@edelstein?source=rss-761b6ecc0758------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lcyU68LZRs4cwcpP8aTGqg.png</url>
            <title>Stories by Ben Edelstein on Medium</title>
            <link>https://medium.com/@edelstein?source=rss-761b6ecc0758------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 20:14:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@edelstein/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Rethinking front-end error reporting]]></title>
            <link>https://medium.com/hackernoon/rethinking-front-end-error-reporting-57c11728314?source=rss-761b6ecc0758------2</link>
            <guid isPermaLink="false">https://medium.com/p/57c11728314</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[error-reporting]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ben Edelstein]]></dc:creator>
            <pubDate>Thu, 08 Feb 2018 19:05:04 GMT</pubDate>
            <atom:updated>2018-02-08T19:05:04.782Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RZ2lM3IngWe8yuIu6KWw5A.png" /></figure><p>Understanding problems in web apps is hard. Between mysterious JavaScript errors, user-reported bugs, and issues caught in QA, there’s a constant struggle to get ahead of the problems affecting your users. And these are just the obvious issues — most bugs are never actually reported since users who have a bad experience just leave or suffer in silence.</p><p>Traditional error-reporting tools (like BugSnag, Sentry, and Rollbar) only solve part of the problem. Originally designed for logging server-side errors, they later added browser SDKs as front-end applications grew more complex. While these tools capture some useful information like stack traces and metadata, many teams find that their alerting is too noisy (too many false positives to be useful), and that they don’t capture enough context to elucidate complicated issues.</p><h3>Front-end is different</h3><p>Investigating front-end and backend errors are very different processes. Server-side code runs on a single platform. Often, the only state in the system that can cause hard-to-reproduce errors comes from easily logged events like database or cache queries. When an unhandled exception in server code takes place, it usually means there is a clear-cut problem that needs to be fixed.</p><p>On the front-end, things aren’t so simple. The average web application runs in over 15 different browsers, across hundreds of device types. State can be highly complex, coming from memory, local storage, local databases, service workers, and APIs. A web app must be robust to connectivity issues and cross-browser differences, and unlike the backend where exceptions are usually clear-cut, it can be tricky to gauge the impact on the frontend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iM58m5_7buKXkbThpykXKw.png" /></figure><p>Given the frequency and diversity of errors that front-end developers see, the most important question becomes, <em>did this affect the user?</em> Unfortunately, looking at just a stack trace and an exception message, it’s very difficult to know. Is this a P0 crippling bug? Or maybe just a nuisance.</p><h3>Answering the right questions</h3><figure><a href="https://www.xkcd.com/1700/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x-zMtnqUPMHnH1_451tCtA.png" /></a><figcaption>You never quite know how things will break. (credit: xkcd.com)</figcaption></figure><p>Two years ago, we started thinking about what the perfect front-end bug report would look like. Clearly, it would collect basic information like a stack trace, metadata, and frequency histograms. But to really gauge the impact on the user, especially for hard-to-reproduce bugs, it has to let you actually <em>see</em> what happened.</p><p>LogRocket is our audacious attempt at doing just that — reproducing an issue as if it happened in your own browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7jjY7mzUUvKKVoumPnNEdA.png" /></figure><h3>It’s all in the video</h3><p>At the center of a LogRocket error report is a pixel-perfect video that accurately captures what the user saw on screen. In order to do this without any performance impact, LogRocket instruments the DOM to record the HTML and CSS on the page at the time of the issue.</p><p>In addition, LogRocket records console logs, JavaScript errors, stacktraces, network requests/responses with headers + bodies, browser metadata, and custom logs. It also has deep integrations with libraries like React, Redux, and Angular to log actions and application state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SEE7Ol9Wlnx6NIuhU7CBlQ.png" /></figure><p>Watching the video is the fastest way to quickly know if an exception actually affected the user. And if it did, you can easily figure out what happened by reviewing network requests, logs, and application state.</p><h3>User-reported bugs</h3><h3>Stan on Twitter</h3><p>@LogRocketJS Hey guys, are you ok? Looks like you&#39;re down https://t.co/ZLZCsvtzc3</p><p>When users ask for help, whether through a help desk, email, or worst of all, on Twitter — it is crucial that support and developers can quickly understand what went wrong. Unfortunately this typically means asking the user for screenshots, logs, and steps to reproduce.</p><p>With LogRocket, you can just search for a user and replay sessions where they encountered issues or asked for support. We’ve built integrations with most help desks like Intercom to let you view the user’s history directly from a chat.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dYWBFW6Bb1R__isM04y87Q.png" /></figure><p>Sometimes, it’s unclear if a user is just confused, or actually experiencing a bug. By reviewing the video replay, console and network logs from their session, you can easily make this distinction.</p><h3>Most bugs aren’t explicit exceptions</h3><p>While monitoring and fixing JavaScript exceptions is crucial to application health, the reality is that the majority of problems users experience aren’t explicit code errors and aren’t ever reported. UI glitches, slow performance, broken interfaces, and even confusing UX all negatively affect user happiness and your bottom line.</p><p>If front-end teams want to be able to ship new features quickly, they must have confidence that these issues are being proactively detected and surfaced.</p><p>Furthermore, issues of any type must be trustworthy — if there are too many false positives, alerts will simply be ignored.</p><h3>Our mission: Surface all front-end problems that negatively affect users</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4XJU0jQ1Q-EyuQ5nvkKXCQ.png" /></figure><p>JavaScript exceptions are just the first type of “issue” that we’ve started surfacing in LogRocket. The telemetry we’re collecting on the front-end lets us detect performance issues, broken interfaces, confusing UX, and more. We’ve started working with a select group of our customers like Reddit, Twitch, and AOL to surface these issues and will be rolling out to more customers in the next few months.</p><p>If you’re an existing LogRocket customer or want to start working with us, <a href="/service/mailto:support@logrocket.com">get in touch</a> and you can join the beta.</p><h3>Front-end is the future</h3><p>The shift toward rich single page apps has undoubtedly improved both user experience quality and developer productivity. But with greater complexity comes the need for more observability. Existing tooling is not yet sufficient for teams to have confidence in the front-end code they ship.</p><p>At LogRocket, we’ve taken what we believe is a big step toward a solution — but there’s lots more work to do. If you want to help define the next generation of tooling for front-end developers, we’d love to meet you. We’re <a href="https://logrocket.com/company">hiring</a> :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57c11728314" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/rethinking-front-end-error-reporting-57c11728314">Rethinking front-end error reporting</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[High Performance React: 3 New Tools to Speed Up Your Apps]]></title>
            <link>https://medium.com/free-code-camp/make-react-fast-again-tools-and-techniques-for-speeding-up-your-react-app-7ad39d3c1b82?source=rss-761b6ecc0758------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ad39d3c1b82</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Ben Edelstein]]></dc:creator>
            <pubDate>Wed, 12 Jul 2017 14:34:53 GMT</pubDate>
            <atom:updated>2017-07-12T14:47:31.067Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mJFYp7LKVzZM3PPjFb0QXQ.png" /></figure><p>React is usually pretty fast, but it’s easy to make small mistakes that lead to performance issues. Slow component mounts, deep component trees, and unnecessary render cycles can quickly add up to an app that feels slow.</p><p>Luckily there are lots of tools, some even built in to React, that help with diagnosing performance issues. In this post I’ll highlight tools and techniques for making React apps fast. Each section also has an interactive, and (hopefully) fun demo!</p><h3>Tool #1: The Performance Timeline</h3><p>React 15.4.0 introduced a new performance timeline feature that lets you see exactly when components get mounted, updated, and unmounted. It also lets you visualize component lifecycles in relation to each other.</p><p><strong>Note: </strong>For now, this feature only works in Chrome, Edge, and IE, since it leverages the User Timing API which has yet to be implemented in all browsers.</p><h4>How it works</h4><ol><li>Open your app and append the query param: react_perf. For example, <a href="http://localhost:3000/?react_perf">http://localhost:3000?react_perf</a></li><li>Open the Chrome DevTools <strong>Performance</strong> tab and press <strong>Record</strong>.</li><li>Perform the actions that you want to analyze.</li><li>Stop recording.</li><li>Inspect the visualization under <strong>User Timing.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cOO5vUnbkdDUcqMW8ebJqA.png" /></figure><h4>Understanding the output</h4><p>Each colored bar shows time that a component is doing “work”. Since JavaScript is single-threaded, whenever a component is mounting or rendering, it’s hogging the main thread and preventing other code from running.</p><p>The text in brackets like [update] describes which part of the component lifecycle is taking place. The timeline breaks down each step, so you can see fine-grained timings on methods like [componentDidMount] [componentWillReceiveProps] [ctor] (constructor) and [render].</p><p>Bars that are stacked represent component trees. While it is typical to have fairly deep component trees in React, if you are optimizing a component that is mounted frequently, it can help to reduce the number of wrapper components since each adds a small performance and memory penalty.</p><p>One caveat here is that the timing numbers in the timeline are for the development build of React, which is much slower than prod. In fact, the performance timeline itself even slows down your app. While these numbers shouldn’t be considered representative of real-world performance, the <em>relative </em>timings between different components are accurate. Also, whether or not a component updates at all is not dependent on a prod build.</p><h4>Demo #1</h4><p>For fun, I rigged the TodoMVC app to have some <em>serious </em>performance problems. You can <a href="https://perf-demo.firebaseapp.com/?react_perf">try it out here</a>.</p><p>To see the timeline, open the Chrome dev tools, go to the “Performance” tab, and click Record. Then add some TODOs in the app, stop the recording, and inspect the timeline. See if you can spot which components are causing the performance problems :)</p><h3>Tool #2: why-did-you-update</h3><p>One of the most common issues that affects performance in React is unnecessary render cycles. By default, React components will re-render whenever their parent renders, even if their props didn’t change.</p><p>For example, if I have a simple component like this:</p><pre>class DumbComponent extends Component {<br>  render() {<br>    return &lt;div&gt; {this.props.value} &lt;/div&gt;;<br>  }<br>}</pre><p>With a parent component like this:</p><pre>class Parent extends Component {<br>  render() {<br>    return &lt;div&gt;<br>      &lt;DumbComponent value={3} /&gt;<br>    &lt;/div&gt;;<br>  }<br>}</pre><p>Whenever the parent component renders, DumbComponent will re-render, despite its props not changing.</p><p>Generally, if render runs, and there were no changes to the virtual DOM, it is a wasted render cycle since the render method should be pure and not have any side effects. In a large-scale React app, it can be tricky to detect places where this happens, but luckily, there’s a tool that can help!</p><h4>Using why-did-you-update</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lb4nr_WLwnLt63jUoszrnQ.png" /></figure><p>why-did-you-update is a library that hooks into React and detects potentially unnecessary component renders. It detects when a component’s render method is called despite its props not having changed.</p><h4>Setup</h4><ol><li>Install with npm: npm i --save-dev why-did-you-update</li><li>Add this snippet anywhere in your app:</li></ol><pre>import React from &#39;react&#39;</pre><pre>if (process.env.NODE_ENV !== &#39;production&#39;) {<br>  const {whyDidYouUpdate} = require(&#39;why-did-you-update&#39;)<br>  whyDidYouUpdate(React)<br>}</pre><p><strong>Note</strong> that this tool is great in local development but make sure it’s disabled in production since it will slow down your app.</p><h4>Understanding the output</h4><p>why-did-you-update monitors your app as it runs and logs components that may have changed unnecessarily. It lets you see the props before and after a render cycle it determined may have been unnecessary.</p><h4>Demo #2</h4><p>To demonstrate why-did-you-update, I installed the library in the TodoMVC app on Code Sandbox, an online React playground. Open the browser console and add some TODOs to see the output.</p><p><a href="https://codesandbox.io/s/xGJP4QExn">Here’s the demo</a>.</p><p>Notice that a few components in the app are rendering unnecessarily. Try implementing the techniques described above to prevent unnecessary renders. If done correctly, there should be no output from why-did-you-update in the console.</p><h3>Tool #3: React Developer Tools</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Ih6h8djFyH13tfFK3D1sw.png" /></figure><p>The React Developer Tools Chrome extension has a built-in feature for visualizing component updates. This is helpful for detecting unnecessary render cycles. To use it, first make sure to <a href="https://codesandbox.io/s/xGJP4QExn">install the extension here</a>.</p><p>Then, open the extension by clicking the “React” tab in the Chrome DevTools and check “Highlight Updates”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GP4vXvW3WO0vTbggDfus4Q.png" /></figure><p>Then, simply use your app. Interact with various components and watch the DevTools work its magic.</p><h4>Understanding the output</h4><p>The React Developer Tools highlights components that are re-rendering at a given point in time. Depending on the frequency of updates, a different color is used. Blue shows infrequent updates, ranging to green, yellow, and red for components that update frequently.</p><p>Seeing yellow or red isn’t <em>necessarily</em> a bad thing. It would be expected when adjusting a slider, or other UI element that triggers frequent updates. But if you click a simple button and see red- it may mean that something is awry. The purpose of the tool is to spot components that are updating <em>unnecessarily</em>. As the app developer, you should have a general idea which components should be updating at a given time.</p><h4>Demo #3</h4><p>To demonstrate the component highlighting, I rigged the TodoMVC app to update some components unnecessarily.</p><p><a href="https://highlight-demo.firebaseapp.com/">Here’s the demo</a>.</p><p>Open the link above, and then open the React Developer Tools and enable update highlighting. When you type in the top text input, you’ll see all of the TODOs highlight unnecessarily. As you type faster, you’ll see the color change to indicate more frequent updates.</p><h3>Fixing unnecessary renders</h3><p>Once you’ve identified components in your app that are re-rendering unnecessarily, there are a few easy fixes.</p><h4>Use PureComponent</h4><p>In the above example, DumbComponent is a pure function of its props. That is, the component only needs to re-render when its props change. React has a special type of component built-in called PureComponent that is meant for exactly this use case.</p><p>Instead of inheriting from React.Component, use React.PureComponent like this:</p><pre>class DumbComponent extends PureComponent {<br>  render() {<br>    return &lt;div&gt; {this.props.value} &lt;/div&gt;;<br>  }<br>}</pre><p>Then, the component will only re-render when its props actually change. That’s it!</p><p>Note that PureComponent does a shallow comparison of props, so if you use complex data structures, it may miss some prop changes and not update your components.</p><h4>Implement shouldComponentUpdate</h4><p>shouldComponentUpdate is a component method called before render when either props or state has changed. If shouldComponentUpdate returns true, render will be called, if it returns false, nothing happens.</p><p>By implementing this method, you can instruct React to avoid re-rendering a given component if its props don’t change.</p><p>For example, we could implement shouldComponentUpdate in our dumb component from above like this:</p><pre>class DumbComponent extends Component {<br>  shouldComponentUpdate(nextProps) {<br>    if (this.props.value !== nextProps.value) {<br>      return true;<br>    } else {<br>      return false;<br>    }<br>  }</pre><pre>render() {<br>    return &lt;div&gt;foo&lt;/div&gt;;<br>  }<br>}</pre><h3>Debugging Performance Issues in Production</h3><p>The React Developer Tools only work if you are running your app on your own machine. If you’re interested in understanding performance issues that users see in production, try <a href="https://logrocket.com/">LogRocket</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_rMyo6NbrAsP-XtvBaXFg.png" /></figure><p><a href="https://logrocket.com/">LogRocket</a> is like a DVR for web apps, recording <em>literally</em> <em>everything</em> that happens on your site. Instead of guessing why problems happen, you can replay sessions with bugs or performance issues to quickly understand the root cause.</p><p>LogRocket instruments your app to record performance data, Redux actions/state, logs, errors, network requests/responses with headers + bodies, and browser metadata. It also records the HTML and CSS on the page, recreating pixel-perfect videos of even the most complex single-page apps.</p><p></p><p>Thanks for reading. I hope these tools and techniques help in your next React project!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ad39d3c1b82" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/make-react-fast-again-tools-and-techniques-for-speeding-up-your-react-app-7ad39d3c1b82">High Performance React: 3 New Tools to Speed Up Your Apps</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Chrome Developer Tools: Next Level Front-End Development Techniques]]></title>
            <link>https://medium.com/hackernoon/mastering-chrome-developer-tools-next-level-front-end-development-techniques-4755649d96ec?source=rss-761b6ecc0758------2</link>
            <guid isPermaLink="false">https://medium.com/p/4755649d96ec</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[chrome-dev-tools]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[logrocket]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ben Edelstein]]></dc:creator>
            <pubDate>Wed, 28 Jun 2017 15:52:26 GMT</pubDate>
            <atom:updated>2017-07-21T04:42:48.692Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OnsbpbUteSOr3vMrvdhuHg.png" /></figure><p>You may already be familiar with the basic features of the Chrome Developer Tools: the DOM inspector, styles panel, and JavaScript console. But there are a number of lesser-known features that can dramatically improve your debugging or app creation workflows.</p><h3>Dark Theme</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MO3U6DyiFUGfZrEaVfKUmw.png" /></figure><p>Chrome comes with a built-in dark theme for the dev tools. You can enable it by clicking the three dots icon in the upper right of the dev tools pane, clicking “settings”, and then toggling the theme.</p><p>I sometimes find this easier on my eyes, and, obviously, it looks much cooler :)</p><h3>Selection Mode</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*AQjQaMp9wyVqIqx5j5TJ5Q.png" /></figure><p>Chrome Developer Tools (DevTools) offer a number of ways to select elements — the most convenient of which is the selection mode.</p><p>This tool, activated by pressing the mouse icon in the upper-left corner of the dev tools panel (or with cmd + shift + c), lets you select elements on the page simply by clicking on them.</p><p>Once activated, you can move your mouse around the page and preview selection, then click to select an element to inspect. <br> <br>This tool is great for quickly selecting an element on the page since hitting cmd + shift + c will open the dev tools and go straight into selection mode.</p><h3>Store as global variable</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*vsnou_CyFAGBvcxX-Vit0g.png" /></figure><p>Inspecting complicated objects that are logged to the console can sometimes be tricky if they have many keys, or contain values that are hard to parse manually. Luckily, Chrome makes it easy to inspect such objects with JavaScript.</p><p>To do so, right click on an object in the console and press “store as global variable”. This stores the object as a global variable accessible in the console called temp1 which you can then work with using JavaScript.</p><h3>Animation Tools</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*P35bfLUPiQnLhUERamb3gw.png" /></figure><p>Recently, the Chrome team added a number of new features for debugging and for creating animations.</p><p>Clicking the dropdown in the upper-left corner of the console reveals an “Animations” pane that lets you limit the speed for all animations on a site.</p><p>You can also pause all animations. This is particularly useful for a site that is buzzing with animated content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RM-KQrhIcJjptijtRsdLVg.png" /><figcaption>The animations viewer lets you individually control the curve for each property</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*K4l8XAtMSr8pD8V4a7T7Xw.png" /><figcaption>CSS animation controller</figcaption></figure><p>Clicking on the purple curve icon in an element’s transition property lets you view the motion curve for an animation, and fine-tune its properties. In addition, you can use the arrow icons to scroll through a list of preset animations to apply to your element.</p><h3>Simulate Element Pseudo State</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gNamJZNnPl7_bptLrO_f7Q.png" /></figure><p>Another handy tool for styling elements is the element state simulator, which is accessed by clicking the :hov icon in the upper-right corner of the Styles panel.</p><p>This tool lets you simulate the element pseudo states of hover, active, focused, and visited and view styles that are associated with those selectors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*YqU3UjPFdUrAUPqLLKN2WA.png" /></figure><p>To add styles for those pseudo states, add a new selector (with the + icon) and add :&lt;state&gt; to the end of the selector string.</p><p>For example, to add a hover rule to an li with class logo, make a new selector, li.logo:hover, and add styles there.</p><p>You can then test your styles by checking the :hover element state to simulate hovering on the element.</p><h3>Prettify CSS and JavaScript</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*mQ5iSM9IFDKiIeHSoLDM4Q.png" /></figure><p>Debugging or viewing minified JavaScript and CSS is very difficult. But luckily DevTools provides a tool that makes doing this a bit easier.</p><p>After opening a minified file in the “Sources” tab, you can click the brackets logo in the lower left corner of the file, and DevTools will “prettify” the code.</p><p>This works quite well with CSS files, and does a decent job with JavaScript, though some information (like variable names) is lost in the minification process.</p><h3>Alt + Up / Alt + Down</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*BN9Mrx_QN_va7uX9foSOww.png" /></figure><p>When debugging CSS, you can select a property and use the up/down keys to tweak it’s value. By default, the arrow keys adjust values by +/- 1. However, by holding the alt key, you can use the arrow keys to adjust values finely in steps of 0.1, which is particularly useful when working with fractional values.</p><p>Conversely, you can hold shift to adjust values in steps of 10.</p><h3>Preserve Log</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*R9-tpjnSs1ssvTki90qlLw.png" /></figure><p>Preserve log is a checkbox that lets you persist logs between page refreshes. This is useful when debugging website issues that require you to refresh the page, since all console output is otherwise cleared.</p><p>When this option is enabled, a new type of “Navigation” log appears in the console to show page refreshes or navigation events to different pages.</p><h3>Network + Log Filters</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*F41OyOeFc3mdvcRGRHYedw.png" /></figure><p>When debugging an app that has a lot of network requests or console logs, it can be useful to filter for particular types of events.</p><p>Chrome has a filtering language that supports many different properties, as well as operators like * to do wildcard matches.</p><p>If you type “-”, Chrome will expose a typeahead that shows the various properties you can filter for. You can also toggle on “regex” mode to do a regex match on the data shown in each row.</p><h3>Code Coverage</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gD8lX40PSemDOZgvT695Mg.png" /></figure><p>Code coverage lets you run your web app, then for each JavaScript and CSS file, see which lines of code ran and which didn’t. This is helpful since when working on a complex or long-term project, it is easy to accumulate dead code.</p><p>To use it, make sure you have Chrome 59 or higher, and go to the “Coverage” tab. Press “record” and then start using your app. When you’re done, Chrome will show you the exact code that ran during your session.</p><h3>Debugging Issues in Production</h3><p>DevTools only works if you’re running your app on your own machine. If you’re interested in understanding bugs and performance issues that users see in production, try <a href="https://logrocket.com/">LogRocket</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_rMyo6NbrAsP-XtvBaXFg.png" /></figure><p><a href="https://logrocket.com/">LogRocket</a> is a front-end logging tool that lets you replay problems as if they happened in your own browser. Instead of guessing why errors happen, or asking users for screenshots and log dumps, LogRocket lets you replay the session to quickly understand what went wrong. It works perfectly with any app, regardless of framework, and has plugins to log additional context from React, Angular, and Vue.js.</p><p>LogRocket instruments your app to record console logs, network requests/responses with headers + bodies, browser metadata, Redux actions/state, and performance timings. It also records the HTML and CSS on the page, recreating pixel-perfect videos of even the most complex single-page apps.</p><p>You can <a href="https://logrocket.com/">check out LogRocket here</a>.</p><p><a href="https://logrocket.com/">LogRocket | Logging and Session Replay for JavaScript Apps</a></p><p>Thanks for reading. I hope these advanced DevTools techniques help you build better apps with less stress.</p><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4755649d96ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/mastering-chrome-developer-tools-next-level-front-end-development-techniques-4755649d96ec">Mastering Chrome Developer Tools: Next Level Front-End Development Techniques</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Maximizing Debuggability with Redux]]></title>
            <link>https://medium.com/hackernoon/maximizing-debuggability-with-redux-2f0bb43054d8?source=rss-761b6ecc0758------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f0bb43054d8</guid>
            <category><![CDATA[logrocket]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[debuggability]]></category>
            <dc:creator><![CDATA[Ben Edelstein]]></dc:creator>
            <pubDate>Wed, 28 Jun 2017 15:49:32 GMT</pubDate>
            <atom:updated>2017-07-21T04:44:54.944Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WmXD6cob1lj38L5StDAUfQ.png" /></figure><p>In my last blog post, <a href="https://blog.logrocket.com/redux-logging-in-production-3b2a4816b713">Redux Logging in Production</a>, I discussed one of the most important benefits of using Redux — debuggability. By using front end logging tools like LogRocket, developers can easily understand and fix tricky bugs in production by reviewing the actions and state changes leading up to a bug.</p><p>While this information is immediately useful in any Redux app, there is a lot more we can achieve by architecting an app with logging in mind. In this post I’m going to look at a few libraries and abstractions that make Redux logs <em>even more</em> useful by putting as much application data through Redux as possible.</p><h3>Data Fetching</h3><p>Fetching/sending data over the network is one of the most bug-prone parts of any app. Issues can arise from connectivity, unexpected data or incorrect logic. And things get extra complicated with polling, retry logic, optimistic mutations, etc.</p><p>Libraries like <strong>apollo-client</strong> for GraphQL, and <strong>redux-query</strong> for REST both facilitate fetching data from the network via Redux. They use Redux as a persistence layer, meaning that when debugging issues, you can inspect your Redux logs to see what data these clients have fetched and what the status is of in-flight requests.</p><p>Lets take a look at the Redux logs generated by redux-query:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H_xAHVS6vKHer0velgQXnw.png" /></figure><p>Here we see the REQUEST_START action, which corresponds with a query being initialized. Looking at the action payload, we see all the information in the request, making it easy to debug. Once a response is received, redux-query emits a REQUEST_SUCCESS action with all the information about the response.</p><p>Logging requests and responses is only part of the magic of redux-query. Digging into the store we see a key queries which is where redux-query persists its internal state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LAQZ7wqFPZRBnh5qOz9hzA.png" /></figure><p>Above, we see objects for each of the queries the app carried out (one to reddit.com/r/frontend.json and one to reddit.com/r/reactjs.json). When debugging issues, we can dig into this state object to see information on in-flight requests, queryCount (if we’re polling on a query), and timings.</p><p>Storing this information in Redux is critical, since it puts full context on all network activity in the Redux logs.</p><h4>Rolling your own data fetching “framework”</h4><p>If you’d prefer a simpler approach, you can roll your own data fetching “framework” by simply dispatching explicit actions when querying and receiving data from the network.</p><p>For example, lets say we’re building a blogging app. When querying for posts, we would dispatch POSTS_QUERY_INIT. The reducer could then update the state appropriately to indicate that the posts query is in progress.</p><pre>postsQuery: {<br>  url: &#39;api.blog.com/posts&#39;,<br>  isPending: true,<br>  ...<br>}</pre><p>In a thunk or saga, we would call fetch and when the promise resolves, we’d dispatch an action like POSTS_QUERY_SUCCESS or POSTS_QUERY_FAILURE. This would then update state appropriately to:</p><pre>postsQuery: {<br>  url: &#39;api.blog.com/posts&#39;,<br>  isPending: true,<br>  data: [...],<br>}</pre><p>This example is far from thorough, but the idea is that by being explicit with Redux actions for each part of the request lifecycle, it becomes easy to debug any potential race condition or network error.</p><h3>Handling other sources of non-determinism</h3><p>In addition to network fetching, there are lots of other sources of non-determinism that can cause bugs. Luckily, we can use Redux for these as well to leave thorough logs in the event of a bug.</p><h4>websockets</h4><p>When listening on a websocket, we can dispatch an action whenever we receive data and reduce it into the store appropriately. For example:</p><pre>myWebSocket.onmessage = function (event) {<br>  store.dispatch({ <br>    type: &#39;BLOG_POST_UPDATE_RECEIVED&#39;,<br>    payload: event,<br>  } <br>}</pre><p>That way, when looking at the Redux logs for an error or user-reported issue, we can see all the data that was received over the websocket and, crucially, relate it in time to other redux actions and network requests.</p><h4>Local Storage</h4><p>Often, an app needs to read from local storage when it first starts up. To do this, you can use redux-storage a handy library that facilitates dumping state to local storage and reading/merging it back into state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v1wTnBtzN6YZENxv3G4XRQ.png" /></figure><p>Whenever redux-storage loads or saves state from redux, it emits an action showing exactly the payload that will get reduced into the store.</p><h4>Everything else…</h4><p>The pattern of dispatching Redux actions for sources of non-determinism applies to most APIs like IndexedDB, or even functions like Date() and Math.random()- consider dispatching Redux actions with the result, so that you can easily debug these in the future.</p><h3>React Router</h3><p>Using react-router-redux lets you synchronize react-router state into Redux. Adding the integration is trivial, and doesn’t require any changes to how you use react-router. Once you get the library set up, you’ll see a new key in your Redux store called routing with information on the current router state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i5lC6-CYMmeE0KF0Y9CHFA.png" /></figure><p>In addition, react-router-redux dispatches actions like @@router/LOCATION_CHANGE when its state changes.</p><p>Also of note is that using react-router-redux lets you rewind router state when time-traveling in redux-devtools, since its state its state is derived from the state in Redux.</p><h3>A note about local vs Redux state</h3><p>I don’t want to get into the debate on local vs Redux state here, but production Redux logging does change the calculus of this decision in some cases. When deciding whether a given piece of state should be in Redux, ask yourself if seeing that state (and the actions that influenced it) could be helpful when debugging issues. If the answer is yes, consider putting that state in Redux so that it will be logged with crash reports and user issues.</p><h3>Production Redux Logging</h3><p>Logging Redux data in production helps you fix bugs and user-reported issues. Check out my previous blog post to learn more:</p><p><a href="https://blog.logrocket.com/redux-logging-in-production-3b2a4816b713">Redux Logging in Production</a></p><h3>TL;DR</h3><p>Using libraries and patterns that put data through Redux helps build more debuggable applications by leaving a rich audit trail.</p><p>When architecting a new feature, ask yourself if it might be error-prone, and whether being able to view its state in the Redux logs would help solve a future bug.</p><p><em>It’s tough to keep up-to-date on front-end dev. Join our weekly mailing list to learn about new tools, libraries and best practices that will help you build better apps:</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F93621c%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2F93621c%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/b367a0893f0b85da4e6a32179081ff1b/href">https://medium.com/media/b367a0893f0b85da4e6a32179081ff1b/href</a></iframe><p><a href="https://logrocket.com/?utm_source=medium&amp;utm_medium=footer"><em>LogRocket</em></a><em> is the JavaScript logging and replay tool that helps you fix bugs, faster. By capturing every log, network request and user session of your app, you can fix problems without back and forth.</em></p><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f0bb43054d8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/maximizing-debuggability-with-redux-2f0bb43054d8">Maximizing Debuggability with Redux</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make React Fast Again [Part 3]: Highlighting Component Updates]]></title>
            <link>https://medium.com/hackernoon/make-react-fast-again-part-3-highlighting-component-updates-798e77dd08d9?source=rss-761b6ecc0758------2</link>
            <guid isPermaLink="false">https://medium.com/p/798e77dd08d9</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[logrocket]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ben Edelstein]]></dc:creator>
            <pubDate>Mon, 12 Jun 2017 16:32:38 GMT</pubDate>
            <atom:updated>2017-07-20T10:39:50.139Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mJFYp7LKVzZM3PPjFb0QXQ.png" /></figure><p>React is usually pretty fast, but it’s easy to make small mistakes that lead to performance issues. Slow component mounts, deep component trees, and unnecessary render cycles can quickly add up to an app that feels slow.</p><p>Luckily there are lots of tools, some even built in to React, that help with diagnosing performance issues. In this series we’ll highlight tools and techniques for making React apps fast. Each post will also have an interactive, and (hopefully) fun demo!</p><h3>Unnecessary Render Cycles [continued]</h3><p>In my <a href="https://blog.logrocket.com/make-react-fast-again-part-2-why-did-you-update-dd1faf79399f">last post</a>, I discussed how unnecessary render cycles can negatively affect performance in React apps. However, in a large-scale app, it can be tricky to know which components are updating at any point in time.</p><h4>Highlight updates with the React Developer Tools</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Ih6h8djFyH13tfFK3D1sw.png" /></figure><p>Luckily, the React Developer Tools Chrome extension has a built in feature for visualizing component updates. To use it, first make sure to install the extension here:</p><p><a href="https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en">React Developer Tools</a></p><p>Then, open the extension by clicking the “React” tab in the Chrome devtools and check “Highlight Updates”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GP4vXvW3WO0vTbggDfus4Q.png" /></figure><p>Then, simply use your app. Interact with various components and watch the devtools work its magic.</p><h4>Understanding the output</h4><p>The React Developer Tools highlights components that are re-rendering at a given point in time. Depending on the frequency of updates, a different color is used. Blue shows infrequent updates, ranging to green, yellow, and red for components that update frequently.</p><p>Seeing yellow or red isn’t <em>necessarily</em> a bad thing. It would be expected when adjusting a slider, or other UI element that triggers frequent updates. But if you click a simple button and see red- it may mean that something is awry. The purpose of the tool is to spot components that are updating <em>unnecessarily</em>. As the app developer, you should have a general idea which components should be updating at a given time.</p><h3>Demo!</h3><p>To demonstrate the component highlighting, I rigged the TodoMVC app to update some components unnecessarily.</p><p><a href="https://highlight-demo.firebaseapp.com/">Redux TodoMVC Example</a></p><p>Open the link above, and then open the React Developer Tools and enable update highlighting. When you type in the top text input, you’ll see all of the TODOs highlight unnecessarily. As you type faster, you’ll see the color change to indicate more frequent updates.</p><h3>Debugging Performance Issues in Production</h3><p>The React Developer Tools only work if you are running your app on your own machine. If you’re interested in understanding performance issues that users see in production, try <a href="https://logrocket.com/">LogRocket</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_rMyo6NbrAsP-XtvBaXFg.png" /></figure><p><a href="https://logrocket.com/">LogRocket</a> is like a DVR for web apps, recording <em>literally</em> <em>everything</em> that happens on your site. Instead of guessing why problems happen, you can replay sessions with bugs or performance issues to quickly understand the root cause.</p><p>LogRocket instruments your app to record performance data, Redux actions/state, logs, errors, network requests/responses with headers + bodies, and browser metadata. It also records the HTML and CSS on the page, recreating pixel-perfect videos of even the most complex single-page apps.</p><p><a href="https://logrocket.com/">Session Replay | Product Analytics | Error Tracking</a></p><h3>Conclusion</h3><p>The highlighting feature in the React Developer Tools is an easy way to quickly see which components are updating as you interact with your app.</p><p>Since this only works locally, check out <a href="https://logrocket.com/">LogRocket</a>, for diagnosing bugs and performance issues in production.</p><p>For more React performance tips, check out part 2 of this series:</p><p><a href="https://blog.logrocket.com/make-react-fast-again-part-2-why-did-you-update-dd1faf79399f">Make React Fast Again [Part 2]: why-did-you-update</a></p><p><em>It’s tough to keep up-to-date on front-end dev. Join our weekly mailing list to learn about new tools, libraries and best practices that will help you build better apps:</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F93621c%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2F93621c%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/71e05e37ed46f2362e5a20526fd38cbe/href">https://medium.com/media/71e05e37ed46f2362e5a20526fd38cbe/href</a></iframe><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=798e77dd08d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/make-react-fast-again-part-3-highlighting-component-updates-798e77dd08d9">Make React Fast Again [Part 3]: Highlighting Component Updates</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Chrome Developer Tools: Next Level Front-End Development Techniques]]></title>
            <link>https://medium.com/free-code-camp/mastering-chrome-developer-tools-next-level-front-end-development-techniques-3ac0b6fe8a3?source=rss-761b6ecc0758------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ac0b6fe8a3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Ben Edelstein]]></dc:creator>
            <pubDate>Mon, 12 Jun 2017 16:05:59 GMT</pubDate>
            <atom:updated>2017-06-12T16:05:59.074Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OnsbpbUteSOr3vMrvdhuHg.png" /></figure><p>You may already be familiar with the basic features of the Chrome Developer Tools: the DOM inspector, styles panel, and JavaScript console. But there are a number of lesser-known features that can dramatically improve your debugging or app creation workflows.</p><h3>Dark Theme</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MO3U6DyiFUGfZrEaVfKUmw.png" /></figure><p>Chrome comes with a built-in dark theme for the dev tools. You can enable it by clicking the three dots icon in the upper right of the dev tools pane, clicking “settings”, and then toggling the theme.</p><p>I sometimes find this easier on my eyes, and, obviously, it looks much cooler :)</p><h3>Selection Mode</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*AQjQaMp9wyVqIqx5j5TJ5Q.png" /></figure><p>Chrome Developer Tools (DevTools) offer a number of ways to select elements — the most convenient of which is the selection mode.</p><p>This tool, activated by pressing the mouse icon in the upper-left corner of the dev tools panel (or with cmd + shift + c), lets you select elements on the page simply by clicking on them.</p><p>Once activated, you can move your mouse around the page and preview selection, then click to select an element to inspect. <br> <br>This tool is great for quickly selecting an element on the page since hitting cmd + shift + c will open the dev tools and go straight into selection mode.</p><h3>Store as global variable</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*vsnou_CyFAGBvcxX-Vit0g.png" /></figure><p>Inspecting complicated objects that are logged to the console can sometimes be tricky if they have many keys, or contain values that are hard to parse manually. Luckily, Chrome makes it easy to inspect such objects with JavaScript.</p><p>To do so, right click on an object in the console and press “store as global variable”. This stores the object as a global variable accessible in the console called temp1 which you can then work with using JavaScript.</p><h3>Animation Tools</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*P35bfLUPiQnLhUERamb3gw.png" /></figure><p>Recently, the Chrome team added a number of new features for debugging and for creating animations.</p><p>Clicking the dropdown in the upper-left corner of the console reveals an “Animations” pane that lets you limit the speed for all animations on a site.</p><p>You can also pause all animations. This is particularly useful for a site that is buzzing with animated content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RM-KQrhIcJjptijtRsdLVg.png" /><figcaption>The animations viewer lets you individually control the curve for each property</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*K4l8XAtMSr8pD8V4a7T7Xw.png" /><figcaption>CSS animation controller</figcaption></figure><p>Clicking on the purple curve icon in an element’s transition property lets you view the motion curve for an animation, and fine-tune its properties. In addition, you can use the arrow icons to scroll through a list of preset animations to apply to your element.</p><h3>Simulate Element Pseudo State</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gNamJZNnPl7_bptLrO_f7Q.png" /></figure><p>Another handy tool for styling elements is the element state simulator, which is accessed by clicking the :hov icon in the upper-right corner of the Styles panel.</p><p>This tool lets you simulate the element pseudo states of hover, active, focused, and visited and view styles that are associated with those selectors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*YqU3UjPFdUrAUPqLLKN2WA.png" /></figure><p>To add styles for those pseudo states, add a new selector (with the + icon) and add :&lt;state&gt; to the end of the selector string.</p><p>For example, to add a hover rule to an li with class logo, make a new selector, li.logo:hover, and add styles there.</p><p>You can then test your styles by checking the :hover element state to simulate hovering on the element.</p><h3>Prettify CSS and JavaScript</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*mQ5iSM9IFDKiIeHSoLDM4Q.png" /></figure><p>Debugging or viewing minified JavaScript and CSS is very difficult. But luckily DevTools provides a tool that makes doing this a bit easier.</p><p>After opening a minified file in the “Sources” tab, you can click the brackets logo in the lower left corner of the file, and DevTools will “prettify” the code.</p><p>This works quite well with CSS files, and does a decent job with JavaScript, though some information (like variable names) is lost in the minification process.</p><h3>Alt + Up / Alt + Down</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*BN9Mrx_QN_va7uX9foSOww.png" /></figure><p>When debugging CSS, you can select a property and use the up/down keys to tweak it’s value. By default, the arrow keys adjust values by +/- 1. However, by holding the alt key, you can use the arrow keys to adjust values finely in steps of 0.1, which is particularly useful when working with fractional values.</p><p>Conversely, you can hold shift to adjust values in steps of 10.</p><h3>Preserve Log</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*R9-tpjnSs1ssvTki90qlLw.png" /></figure><p>Preserve log is a checkbox that lets you persist logs between page refreshes. This is useful when debugging website issues that require you to refresh the page, since all console output is otherwise cleared.</p><p>When this option is enabled, a new type of “Navigation” log appears in the console to show page refreshes or navigation events to different pages.</p><h3>Network + Log Filters</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*F41OyOeFc3mdvcRGRHYedw.png" /></figure><p>When debugging an app that has a lot of network requests or console logs, it can be useful to filter for particular types of events.</p><p>Chrome has a filtering language that supports many different properties, as well as operators like * to do wildcard matches.</p><p>If you type “-”, Chrome will expose a typeahead that shows the various properties you can filter for. You can also toggle on “regex” mode to do a regex match on the data shown in each row.</p><h3>Code Coverage</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gD8lX40PSemDOZgvT695Mg.png" /></figure><p>Code coverage lets you run your web app, then for each JavaScript and CSS file, see which lines of code ran and which didn’t. This is helpful since when working on a complex or long-term project, it is easy to accumulate dead code.</p><p>To use it, make sure you have Chrome 59 or higher, and go to the “Coverage” tab. Press “record” and then start using your app. When you’re done, Chrome will show you the exact code that ran during your session.</p><h3>Debugging Issues in Production</h3><p>DevTools only works if you’re running your app on your own machine. If you’re interested in understanding bugs and performance issues that users see in production, try <a href="https://logrocket.com/">LogRocket</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_rMyo6NbrAsP-XtvBaXFg.png" /></figure><p><a href="https://logrocket.com/">LogRocket</a> is a front-end logging tool that lets you replay problems as if they happened in your own browser. Instead of guessing why errors happen, or asking users for screenshots and log dumps, LogRocket lets you replay the session to quickly understand what went wrong. It works perfectly with any app, regardless of framework, and has plugins to log additional context from React, Angular, and Vue.js.</p><p>LogRocket instruments your app to record console logs, network requests/responses with headers + bodies, browser metadata, Redux actions/state, and performance timings. It also records the HTML and CSS on the page, recreating pixel-perfect videos of even the most complex single-page apps.</p><p>You can <a href="https://logrocket.com/">check out LogRocket here</a>.</p><p><a href="https://logrocket.com/">LogRocket | Logging and Session Replay for JavaScript Apps</a></p><p>Thanks for reading. I hope these advanced DevTools techniques help you build better apps with less stress.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ac0b6fe8a3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/mastering-chrome-developer-tools-next-level-front-end-development-techniques-3ac0b6fe8a3">Mastering Chrome Developer Tools: Next Level Front-End Development Techniques</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make React Fast Again [Part 2]: why-did-you-update]]></title>
            <link>https://medium.com/hackernoon/make-react-fast-again-part-2-why-did-you-update-43a89dc96b10?source=rss-761b6ecc0758------2</link>
            <guid isPermaLink="false">https://medium.com/p/43a89dc96b10</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[make-react-fast-again]]></category>
            <category><![CDATA[react-performance]]></category>
            <category><![CDATA[facebook-react]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ben Edelstein]]></dc:creator>
            <pubDate>Fri, 09 Jun 2017 16:48:51 GMT</pubDate>
            <atom:updated>2017-07-20T10:24:39.926Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mJFYp7LKVzZM3PPjFb0QXQ.png" /></figure><p>React is usually pretty fast, but it’s easy to make small mistakes that lead to performance issues. Slow component mounts, deep component trees, and unnecessary render cycles can quickly add up to an app that feels slow.</p><p>Luckily there are lots of tools, some even built in to React, that help with diagnosing performance issues. In this series we’ll highlight tools and techniques for making React apps fast. Each post will also have an interactive, and (hopefully) fun demo!</p><h3>The Problem: Unnecessary Render Cycles</h3><p>One of the most common issues that affects performance in React is unnecessary render cycles. By default, React components will re-render whenever their parent renders, even if their props didn’t change.</p><p>For example, if I have a simple component like this:</p><pre>class DumbComponent extends Component {<br>  render() {<br>    return &lt;div&gt; {this.props.value} &lt;/div&gt;;<br>  }<br>}</pre><p>With a parent component like this:</p><pre>class Parent extends Component {<br>  render() {<br>    return &lt;div&gt;<br>      &lt;DumbComponent value={3} /&gt;<br>    &lt;/div&gt;;<br>  }<br>}</pre><p>Whenever the parent component renders, DumbComponent will re-render, despite its props not changing.</p><p>Generally, if render runs, and there were no changes to the virtual DOM, it is a wasted render cycle since the render method should be pure and not have any side effects. In a large-scale React app, it can be tricky to detect places where this happens, but luckily, there’s a tool that can help!</p><h3>Why did you update?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lb4nr_WLwnLt63jUoszrnQ.png" /></figure><p>why-did-you-update is a library that hooks into React and detects potentially unnecessary component renders. It detects when a component’s render method is called despite its props not having changed.</p><h4>Setup</h4><ol><li>Install with npm: npm i --save-dev why-did-you-update</li><li>Add this snippet anywhere in your app:</li></ol><pre>import React from &#39;react&#39;</pre><pre>if (process.env.NODE_ENV !== &#39;production&#39;) {<br>  const {whyDidYouUpdate} = require(&#39;why-did-you-update&#39;)<br>  whyDidYouUpdate(React)<br>}</pre><p><strong>Note</strong> that this tool is great in local development but make sure it’s disabled in production since it will slow down your app.</p><h4>Understanding the output</h4><p>why-did-you-update monitors your app as it runs and logs components that may have changed unnecessarily. It lets you see the props before and after a render cycle it determined may have been unnecessary.</p><h3>Fixing unnecessary renders</h3><p>Once you’ve identified components in your app that are re-rendering unnecessarily, there are a few easy fixes.</p><h4>Use PureComponent</h4><p>In the above example, DumbComponent is a pure function of its props. That is, the component only needs to re-render when its props change. React has a special type of component built-in called PureComponent that is meant for exactly this use case.</p><p>Instead of inheriting from React.Component, use React.PureComponent like this:</p><pre>class DumbComponent extends PureComponent {<br>  render() {<br>    return &lt;div&gt; {this.props.value} &lt;/div&gt;;<br>  }<br>}</pre><p>Then, the component will only re-render when its props actually change. That’s it!</p><p>Note that PureComponent does a shallow comparison of props, so if you use complex data structures, it may miss some prop changes and not update your components.</p><h4>Implement shouldComponentUpdate</h4><p>shouldComponentUpdate is a component method called before render when either props or state has changed. If shouldComponentUpdate returns true, render will be called, if it returns false, nothing happens.</p><p>By implementing this method, you can instruct React to avoid re-rendering a given component if its props don’t change.</p><p>For example, we could implement shouldComponentUpdate in our dumb component from above like this:</p><pre>class DumbComponent extends Component {<br>  shouldComponentUpdate(nextProps) {<br>    if (this.props.value !== nextProps.value) {<br>      return true;<br>    } else {<br>      return false;<br>    }<br>  }</pre><pre>render() {<br>    return &lt;div&gt;foo&lt;/div&gt;;<br>  }<br>}</pre><h3>Demo!</h3><p>To demonstrate why-did-you-update, I installed the library in the TodoMVC app on Code Sandbox, an online React playground. Open the browser console and add some TODOs to see the output.</p><p><a href="https://codesandbox.io/s/xGJP4QExn">https://codesandbox.io/s/xGJP4QExn</a></p><p>Notice that a few components in the app are rendering unnecessarily. Try implementing the techniques described above to prevent unnecessary renders. If done correctly, there should be no output from why-did-you-update in the console.</p><h3>Debugging Performance Issues in Production</h3><p>why-did-you-update only works in local development. If you’re interested in understanding performance issues in your production app, try <a href="https://logrocket.com/">LogRocket</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_rMyo6NbrAsP-XtvBaXFg.png" /></figure><p><a href="https://logrocket.com/">LogRocket</a> is a frontend logging tool that lets you replay problems as if they happened in your own browser. Instead of guessing why errors happen, or asking users for screenshots and log dumps, LogRocket lets you replay the session to quickly understand what went wrong.</p><p>LogRocket instruments your app to record performance timings, Redux actions/state, logs, errors, network requests/responses with headers + bodies, and browser metadata. It also records the HTML and CSS on the page, recreating pixel-perfect videos of even the most complex single-page apps.</p><p><a href="https://logrocket.com/">Session Replay | Product Analytics | Error Tracking</a></p><h3>Conclusion</h3><p>why-did-you-update is a handy tool for detecting potentially unnecessary component re-renders, helping you make your app perform better.</p><p>Since why-did-you-update only works in development, check out <a href="https://logrocket.com/">LogRocket</a>, for diagnosing bugs and performance issues in production.</p><p>For more React performance tips, check out parts 1 and 3 of this series:</p><ul><li><a href="https://blog.logrocket.com/make-react-fast-again-part-1-performance-timeline-f7f39f676f58">Make React Fast Again [Part 1]: Performance Timeline</a></li><li><a href="https://blog.logrocket.com/make-react-fast-again-part-3-highlighting-component-updates-6119e45e6833">Make React Fast Again [Part 3]: Highlighting Component Updates</a></li></ul><p><em>It’s tough to keep up-to-date on front-end dev. Join our weekly mailing list to learn about new tools, libraries and best practices that will help you build better apps:</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F93621c%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2F93621c%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/71e05e37ed46f2362e5a20526fd38cbe/href">https://medium.com/media/71e05e37ed46f2362e5a20526fd38cbe/href</a></iframe><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43a89dc96b10" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/make-react-fast-again-part-2-why-did-you-update-43a89dc96b10">Make React Fast Again [Part 2]: why-did-you-update</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make React Fast Again [Part 1]: Performance Timeline]]></title>
            <link>https://medium.com/hackernoon/make-react-fast-again-part-1-performance-timeline-b70176a1df5f?source=rss-761b6ecc0758------2</link>
            <guid isPermaLink="false">https://medium.com/p/b70176a1df5f</guid>
            <category><![CDATA[facebook-react]]></category>
            <category><![CDATA[performance-timeline]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-speed]]></category>
            <category><![CDATA[make-react-fast-again]]></category>
            <dc:creator><![CDATA[Ben Edelstein]]></dc:creator>
            <pubDate>Wed, 07 Jun 2017 12:11:01 GMT</pubDate>
            <atom:updated>2017-07-19T18:29:33.847Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mJFYp7LKVzZM3PPjFb0QXQ.png" /></figure><p>React is usually pretty fast, but it’s easy to make small mistakes that lead to performance issues. Slow component mounts, deep component trees, and unnecessary render cycles can quickly add up to an app that feels slow.</p><p>Luckily there are lots of tools, some even built in to React, that help with diagnosing performance issues. In this series we’ll highlight tools and techniques for making React apps fast. Each post will also have an interactive, and (hopefully) fun demo!</p><h3>Performance timeline</h3><p>React 15.4.0 introduced a new performance timeline feature that lets you see exactly when components get mounted, updated, and unmounted. It also lets you visualize component lifecycles in relation to each other.</p><p><strong>Note: </strong>For now, this feature only works in Chrome, Edge, and IE, since it leverages the User Timing API which has yet to be implemented in all browsers.</p><h4>How it works</h4><ol><li>Open your app and append the query param: react_perf. For example, <a href="http://localhost:3000/?react_perf">http://localhost:3000?react_perf</a></li><li>Open the Chrome DevTools <strong>Performance</strong> tab and press <strong>Record</strong>.</li><li>Perform the actions that you want to analyze.</li><li>Stop recording.</li><li>Inspect the visualization under <strong>User Timing.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cOO5vUnbkdDUcqMW8ebJqA.png" /></figure><h4>Understanding the output</h4><p>Each colored bar shows time that a component is doing “work”. Since JavaScript is single-threaded, whenever a component is mounting or rendering, it’s hogging the main thread and preventing other code from running.</p><p>The text in brackets like [update] describes which part of the component lifecycle is taking place. The timeline breaks down each step, so you can see fine-grained timings on methods like [componentDidMount] [componentWillReceiveProps] [ctor] (constructor) and [render].</p><p>Bars that are stacked represent component trees. While it is typical to have fairly deep component trees in React, if you are optimizing a component that is mounted frequently, it can help to reduce the number of wrapper components since each adds a small performance and memory penalty.</p><p>One caveat here is that the timing numbers in the timeline are for the development build of React, which is much slower than prod. In fact, the performance timeline itself even slows down your app. While these numbers shouldn’t be considered representative of real-world performance, the <em>relative </em>timings between different components are accurate. Also, whether or not a component updates at all is not dependent on a prod build.</p><h3>Demo!</h3><p>For fun, I rigged the TodoMVC app to have some <em>serious </em>performance problems. You can try it out here:</p><p><a href="https://perf-demo.firebaseapp.com/?react_perf">Redux TodoMVC Example</a></p><p>To see the timeline, open the Chrome dev tools, go to the “Performance” tab, and click Record. Then add some TODOs in the app, stop the recording, and inspect the timeline. See if you can spot which components are causing the performance problems :)</p><h3>Debugging Performance Issues in Production</h3><p>The performance timeline feature in React only works in local development, since it gets compiled out of React’s production build. If you’re interested in understanding performance issues in your production app, try <a href="https://logrocket.com/">LogRocket</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_rMyo6NbrAsP-XtvBaXFg.png" /></figure><p><a href="https://logrocket.com/">LogRocket</a> is like a DVR for web apps, recording <em>literally</em> <em>everything</em> that happens on your site. Instead of guessing why problems happen, you can replay sessions with bugs or performance issues to quickly understand the root cause.</p><p>LogRocket instruments your app to record performance timings, Redux actions/state, logs, errors, network requests/responses with headers + bodies, and browser metadata. It also records the HTML and CSS on the page, recreating pixel-perfect videos of even the most complex single-page apps.</p><p><a href="https://logrocket.com/">Session Replay | Product Analytics | Error Tracking</a></p><h3>Conclusion</h3><p>react_perf is a fantastic tool for visualizing React component lifecycles. It lets you quickly see which components are updating, and which might be slowing down your app.</p><p>Since react_perf only works in development, check out <a href="https://logrocket.com/">LogRocket</a>, for diagnosing bugs and performance issues in production.</p><p><em>It’s tough to keep up-to-date on front-end dev. Join our weekly mailing list to learn about new tools, libraries and best practices that will help you build better apps:</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F93621c%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2F93621c%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/71e05e37ed46f2362e5a20526fd38cbe/href">https://medium.com/media/71e05e37ed46f2362e5a20526fd38cbe/href</a></iframe><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b70176a1df5f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/make-react-fast-again-part-1-performance-timeline-b70176a1df5f">Make React Fast Again [Part 1]: Performance Timeline</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redux Logging in Production]]></title>
            <link>https://medium.com/hackernoon/redux-logging-in-production-d489d614de78?source=rss-761b6ecc0758------2</link>
            <guid isPermaLink="false">https://medium.com/p/d489d614de78</guid>
            <category><![CDATA[redux-logging]]></category>
            <category><![CDATA[production]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[understanding-problems]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Ben Edelstein]]></dc:creator>
            <pubDate>Fri, 02 Jun 2017 16:35:47 GMT</pubDate>
            <atom:updated>2017-07-19T17:20:15.589Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TMvybHHWRGUicsH7LtET9A.png" /></figure><p>Understanding problems in web apps is hard. Between mysterious JavaScript errors, user-reported bugs, and issues caught in QA, there’s a constant struggle to get ahead of the problems affecting your users. And these are just the obvious issues — most bugs are never actually reported since users who have a bad experience just leave or suffer in silence.</p><p>To solve this problem, developers are increasingly adopting frontend logging tools, since modern state management libraries like Redux leave a rich audit trail. Logging actions and state in production makes it easy to understand bugs and user-reported issues.</p><p>In this post, I’ll show you how to set up Redux logging with LogRocket. Then, I’ll discuss techniques for making Redux apps easier to debug.</p><h3>LogRocket: a DVR for web apps</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_rMyo6NbrAsP-XtvBaXFg.png" /></figure><p><a href="https://logrocket.com/">LogRocket</a> is a frontend logging tool that lets you replay problems as if they happened in your own browser. Instead of guessing why errors happen, or asking users for screenshots and log dumps, LogRocket lets you replay the session to quickly understand what went wrong. It works perfectly with any app, regardless of framework, and has plugins to log additional context from Redux, Vuex, and @ngrx/store.</p><p>In addition to logging Redux actions and state, LogRocket records console logs, JavaScript errors, stacktraces, network requests/responses with headers + bodies, browser metadata, and custom logs. It also instruments the DOM to record the HTML and CSS on the page, recreating pixel-perfect videos of even the most complex single page apps.</p><h3>Setting up LogRocket</h3><p>Setting up LogRocket is easy, and only requires adding a few lines of code to your app:</p><ol><li>Install with NPM: npm i --save logrocket.</li><li>Create a free account at <a href="https://app.logrocket.com/">https://app.logrocket.com</a>, and take note of your application id.</li><li>Initialize LogRocket in your app:</li></ol><pre>import LogRocket from &#39;logrocket&#39;;</pre><pre>// Initialize LogRocket with your app ID<br>LogRocket.init(&lt;your_application_id&gt;);</pre><p>4. Add the Redux middleware.</p><pre>import { applyMiddleware, createStore } from &#39;redux&#39;;</pre><pre>const store = createStore(<br>  reducer, // your app reducer<br>  applyMiddleware(middlewares, LogRocket.reduxMiddleware()),<br>);</pre><p>That’s it for the basic setup- this is all you need to get started with LogRocket!</p><p>LogRocket also has plugins for alternate Flux implementations like <strong>ngrx </strong>and<strong> vuex</strong>, which you can read about <a href="https://docs.logrocket.com/">here</a>.</p><h3>Replaying User Sessions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wMR7GLnb4tFr_BGtHWDdng.png" /></figure><p>Replaying a session in LogRocket is like seeing it happen in your own browser. You can inspect Redux actions with the full action payload as well as the previous and next states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*04LiMHudqAfQRjJAgFSHsA.png" /></figure><p>LogRocket captures both network requests and responses and lets you dig in to specific requests and see the headers and body. The waterfall chart shows timings, making it easy to see which requests were slow, or if a potential race condition occurred.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*DyC3ZdR8nBmLwfs-0_D3GA.png" /></figure><p>Sometimes Redux logs alone aren’t enough to understand a bug, especially when dealing with user-reported issues. LogRocket’s video replay helps here by letting you see exactly what a user saw in your app.</p><p>Since this video is actually a reconstruction of the DOM (and not a real video) you can inspect HTML/CSS to understand visual bugs, or play at 2x speed to gain a quick understanding of what a user did in the app when handling support issues.</p><h3>Integrating Redux logging into your workflow</h3><p>Being able to replay user sessions and see Redux logs is helpful across the development workflow.</p><h4><strong>Fixing Bugs</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6fTDtvXA96V622yi9LtxoQ.png" /></figure><p>LogRocket integrates with error reporting tools like Sentry and Bugsnag, letting you see Redux logs and video for every bug. This is not only helpful for fixing bugs, but also for understanding error impact, since some JavaScript errors are completely innocuous. By watching the video from when an error occurred, you can easily tell if it actually affects users, or can be ignored.</p><h4><strong>Support</strong></h4><p>All too often, users will report issues but not give enough context to figure out exactly what happened.</p><p>If you are using a chat support tool like <a href="https://intercom.com/">Intercom</a>, you can integrate LogRocket directly so that it adds a note with a recording URL whenever a user starts chatting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mUcIXjRe7JA_rOJ1YICiKg.png" /></figure><p>If you are integrating with a more general analytics tool, you can add recording URL’s with a tracking API like this:</p><pre>LogRocket.getSessionURL(function (sessionURL) {<br>  analytics.track(&#39;LogRocket recording&#39;, sessionURL);<br>})</pre><h3>Making the most of production Redux logging</h3><p>Production logging is immediately useful in all Redux apps, but by architecting your app with logging in mind, you can ensure that logs are maximally useful when debugging issues.</p><h4><strong>Try to keep most state in Redux</strong></h4><p>I don’t want to get into the debate on local vs Redux state here, but when deciding whether a given piece of state should be in Redux, ask yourself if seeing that state could be helpful when debugging issues. If the answer is yes, consider putting that state in Redux so that it will be logged with crash reports and user issues.</p><h4><strong>Use data fetching libraries that leverage Redux</strong></h4><p>Libraries like <strong>apollo-client</strong> for GraphQL, and <strong>redux-query</strong> for REST both facilitate fetching data from the network via Redux. They use Redux as a persistence layer, meaning that when debugging issues, you can inspect your Redux logs to see what data these clients have fetched.</p><p>If you’d prefer a simpler approach, you can roll your own data fetching “framework” by simply dispatching explicit actions when querying and receiving data from the network.</p><h4><strong>Use Redux to handle sources of non-determinism</strong></h4><p>When accessing data from APIs like websockets, local storage, IndexedDB, or even Date(), consider dispatching Redux actions with the result, so that you can easily debug these in the future. For example, when listening on a websocket, dispatch a Redux action on every message- that way you can see the data in your Redux logs.</p><h4><strong>Leverage other console APIs</strong></h4><p>Console methods like console.time(), console.count() and console.group() let you add rich data to your logs like React component render counts, transaction timings and component lifecycle logs. If you’re interested in learning more, I wrote a post about this <a href="https://blog.logrocket.com/leveraging-the-console-api-in-react-apps-44df6d1ebeb2">here</a>.</p><h4><strong>Build and upload source maps to LogRocket</strong></h4><p>LogRocket supports source maps which you can upload via a <a href="https://github.com/LogRocket/logrocket-cli">cli</a>. By doing this you can see symbolicated stack traces for JavaScript errors, Redux actions, console logs and network requests, which lets you see where particular actions were triggered in your code.</p><h3>Conclusion</h3><p>React and Redux are often lauded as tools for building <em>maintainable</em> applications — a significant component of which is <em>debuggability</em>. Logging Redux data in production gives such insight since bugs and other user-reported issues can be easily debugged by inspecting Redux state, network requests and the DOM.</p><p>Using LogRocket for Redux logging can greatly simplify fixing bugs and supporting your users. You can learn more here:</p><p><a href="https://logrocket.com/">LogRocket | Logging and Session Replay for JavaScript Apps</a></p><blockquote>I love <a href="https://medium.com/@edelstein">writing</a> about React, Redux, and other developer tools. If you have any thoughts or comments feel free to leave them here or chat with me on twitter @b_edelstein. Thanks for reading!</blockquote><figure><a href="http://bit.ly/HackernoonFB"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hqOaABQ7XGPT-OYNgiUBg.png" /></a></figure><figure><a href="https://goo.gl/k7XYbx"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vgw1jkA6hgnvwzTsfMlnpg.png" /></a></figure><figure><a href="https://goo.gl/4ofytp"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gKBpq1ruUi0FVK2UM_I4tQ.png" /></a></figure><blockquote><a href="http://bit.ly/Hackernoon">Hacker Noon</a> is how hackers start their afternoons. We’re a part of the <a href="http://bit.ly/atAMIatAMI">@AMI</a> family. We are now <a href="http://bit.ly/hackernoonsubmission">accepting submissions</a> and happy to <a href="/service/mailto:partners@amipublications.com">discuss advertising &amp; sponsorship</a> opportunities.</blockquote><blockquote>If you enjoyed this story, we recommend reading our <a href="http://bit.ly/hackernoonlatestt">latest tech stories</a> and <a href="https://hackernoon.com/trending">trending tech stories</a>. Until next time, don’t take the realities of the world for granted!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35tCjoPcvq6LbB3I6Wegqw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d489d614de78" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/redux-logging-in-production-d489d614de78">Redux Logging in Production</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>