<?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 elsdoerfer on Medium]]></title>
        <description><![CDATA[Stories by elsdoerfer on Medium]]></description>
        <link>https://medium.com/@elsdoerfer?source=rss-1a2658cd8a4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*aYr-XXS5hfuU1KYu.jpeg</url>
            <title>Stories by elsdoerfer on Medium</title>
            <link>https://medium.com/@elsdoerfer?source=rss-1a2658cd8a4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 20:00:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@elsdoerfer/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[Iran and the Verfassungsschutzbericht 2018]]></title>
            <link>https://medium.com/@elsdoerfer/iran-and-the-verfassungsschutzbericht-2018-78d735f36b0?source=rss-1a2658cd8a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/78d735f36b0</guid>
            <category><![CDATA[iran]]></category>
            <category><![CDATA[nuclear-proliferation]]></category>
            <category><![CDATA[journalism]]></category>
            <category><![CDATA[jcpoa]]></category>
            <dc:creator><![CDATA[elsdoerfer]]></dc:creator>
            <pubDate>Wed, 29 May 2019 11:54:12 GMT</pubDate>
            <atom:updated>2019-05-29T11:55:49.597Z</atom:updated>
            <content:encoded><![CDATA[<p>A couple weeks ago, the state of Bavaria released its annual &quot;intelligence report&quot; (Verfassungsschutzbericht). Apparently they mentioned Iran, which caused Benjamin Weinthal at an outlet of the Jerusalem Post to write: <a href="https://www.jpost.com/Middle-East/German-intel-Iran-wants-to-expand-to-weapons-of-mass-destruction-590933">GERMAN INTEL: IRAN WANTS TO EXPAND TO WEAPONS OF MASS DESTRUCTION</a>. He also got to write this for <a href="https://www.foxnews.com/world/iran-military-weapons-of-mass-destruction-germany">Fox News</a>, the <a href="https://twitter.com/BenWeinthal/status/1133657427503718402">Daily Mail</a> picked it up, and I have no doubt others.</p><p>This raised my suspicious for two reasons: First, the idea that the <em>Verfassungsschutzbericht of Bavaria</em> is going to contain any intelligence scoops seems quite far-fetched, and also, this whole thing felt overly familiar.</p><p>Now despite of the impression you might get from reading above reporting, these reports are not exactly classified material, so we can just go and have a look at the <a href="http://www.verfassungsschutz.bayern.de/mam/anlagen/vsb-2018.pdf">2018 version</a>. Which page are we looking at?</p><h3>Benjamin Weinthal on Twitter</h3><p>@elsdoerfer @aCoerper_Mainz Andrea, See pages 291 and 292 in Bavarian intelligence report. I quoted directly from those pages. Not sure if @elsdoerfer can read German. German intelligence contradicts the Merkel administration&#39;s faith in the JCPOA. Iran sought missile/rocket technology, notes report.</p><p>The relevant section of page 291 is here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uoskqa5DpQoYm2bOyyy_LA.png" /></figure><p>After explaining what &quot;proliferation&quot; means, it goes on:</p><blockquote>So-called risk states, like Iran, North Korea, Syria and Pakistan, endeavor to complement their arsenal of conventional weapons with weapons of mass destruction. To acquire the necessary know-how and the required building parts, those states try to establish business contacts in technically highly developed countries such as Germany.</blockquote><p>You&#39;ll be excused if this reads more like an introductory paragraph to you than hard hitting new intelligence.</p><p>What did the report say in <a href="http://www.verfassungsschutz.bayern.de/mam/anlagen/verfassungsschutzbericht2017_180326.pdf">2017</a> (page 266)?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9gmL8g6HrTwEscDjVpOIcA.png" /></figure><p>Oh, it&#39;s the same text, verbatim. Let&#39;s go back further:</p><h4><a href="http://www.verfassungsschutz.bayern.de/mam/anlagen/verfassungsschutzbericht_bayern_2016.pdf">2016 (page 263)</a>:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y9_9Wc_vXtYktL33LO11bA.png" /></figure><p>Again, verbatim.</p><h4><a href="http://www.verfassungsschutz.bayern.de/mam/anlagen/vsb_2015_druckfassung.pdf">2015 (page 229)</a>:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_9qWLA3dD_Du8zIn3D0jsA.png" /></figure><p>The same copy.</p><h4><a href="http://www.verfassungsschutz.bayern.de/mam/anlagen/barrierearme_version_verfassungsschutzbericht_2014.pdf">2014 (page 202):</a></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*KNYvko2Zd7TaPSi0F-XBbQ.png" /></figure><p>Back in 2014, they still took the time to fully spell &quot;Sogenannte&quot;, rather than abbreviating it — which now that I think about it, is pretty sloppy. I mean, it&#39;s a 400 page report, there is space enough.</p><h4><a href="https://web.archive.org/web/20141103202757/http://www.stmi.bayern.de/assets/stmi/sus/verfassungsschutz/vsb_2013.pdf">2013 (page 194):</a></h4><p>You can tell by the decreasing page numbers that despite the use of abbreviations, the report seems to be getting longer in recent years. The link to the 2013 report is dead on their site, but it is on <a href="https://web.archive.org/web/20141103202757/http://www.stmi.bayern.de/assets/stmi/sus/verfassungsschutz/vsb_2013.pdf">archive.org</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cvtRNZ9W6HPrgQMceBBXmA.png" /></figure><p>It&#39;s a different text! Yes, it still says exactly thesame thing, but they phrased it differently.</p><p>I couldn&#39;t find the reports from the years before.</p><p>I don&#39;t think any of this is news to Mr. Weinthal, who wrote <a href="https://www.jpost.com/Middle-East/German-intel-Iran-wants-to-expand-weapons-into-nuclear-arsenal-561382">basically the same story about last years report</a>, and on the very same day, <a href="https://www.jpost.com/Diaspora/Intel-report-Iran-seeks-weapons-of-mass-destruction-technology-in-Germany-558983">another one about the Verfassungsschutzbericht of yet another German state</a>.</p><p>You decide if this sounds like a scoop to you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78d735f36b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fixing "resource" errors in Android gradle builds]]></title>
            <link>https://medium.com/@elsdoerfer/fixing-resource-errors-in-android-gradle-builds-d5921ab19d38?source=rss-1a2658cd8a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5921ab19d38</guid>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[elsdoerfer]]></dc:creator>
            <pubDate>Sat, 20 Oct 2018 13:53:51 GMT</pubDate>
            <atom:updated>2018-10-20T13:53:51.823Z</atom:updated>
            <content:encoded><![CDATA[<h3>Fixing &quot;resource not found&quot; errors in Android gradle builds</h3><p>I&#39;ve recently had a hell of a time trying to get an Android project (specifically, a react-native project) to build for production. Calling assembleRelease, I kept keeping errors such as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbcf3e5dc060d423d9dd809d0907c660/href">https://medium.com/media/dbcf3e5dc060d423d9dd809d0907c660/href</a></iframe><p>Or, maybe your error talks about android:attr/ttcIndex or android:attr/fontVariationsSettings.</p><p>After a while, I noticed that this error happens only the first time assembleRelease is called after a clean — after that , the build succeeds, until the clean is invoked again. I assume, but have not verified, that those binaries would then cause trouble in production.</p><p>The internet tends to suggest things that involve upgrading the compileSdkVersion, or the build tools version, or other things. Nothing would help. Now because I am using react-native, I have probably an unusual amount of library dependencies, all of which have their own build.gradle files with their own compileSdkVersion. More, some of them allow this value to be overwritten. It&#39;s a bit of a mess.</p><p>After <strong>a lot</strong> of commenting out, reinstating, rebuilding, I tracked it down to the following issue:</p><ul><li>We use a certain version of Android Gradle Plugin (say <em>3.1.4</em>).</li><li>Each version of the plugin requires a minimum <em>&quot;Android Build Tools&quot; </em>version. Maybe the minimum version is 27.</li><li>Your third party dependency declares a version of buildToolsVersion<em>. </em>Maybe the version is set to 23.</li><li>The version set gets ignored in favor of the minimum version. So the third party module is actually compiled with version 27 of the build tools.</li><li>However, that third party module also has a compileSdkVersion set, which is not automatically adjusted along with buildToolsVersion.</li><li>Now it seems that not every buildToolsVersion works with every compileSdkVersion. If those two are incompatible, the errors above might occur. That is, an upgraded version of the build tools has trouble building an older compileSdkVersion.</li></ul><p>The solution then is to make sure that every dependency that is upgraded to a different build tools version needs to have it&#39;s compileSdkVersion updated — some of them support this via a global variable. If they do not, those dependencies need to be patched.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5921ab19d38" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[To defend open platforms, we need to defend Facebook]]></title>
            <link>https://medium.com/@elsdoerfer/to-defend-open-platforms-we-need-to-defend-facebook-7d060ceb0f7e?source=rss-1a2658cd8a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d060ceb0f7e</guid>
            <category><![CDATA[privacy]]></category>
            <category><![CDATA[cambridge-analytica]]></category>
            <category><![CDATA[data-breach]]></category>
            <category><![CDATA[facebook]]></category>
            <dc:creator><![CDATA[elsdoerfer]]></dc:creator>
            <pubDate>Thu, 29 Mar 2018 22:22:20 GMT</pubDate>
            <atom:updated>2018-03-29T22:22:51.989Z</atom:updated>
            <content:encoded><![CDATA[<p>Supposedly we are angry because millions of data records where leaked in a breach. Except if that were all that matters, we wouldn&#39;t read claims such as &quot;<em>[</em><a href="https://www.theguardian.com/technology/2018/mar/24/cambridge-analytica-week-that-shattered-facebook-privacy"><em>Facebook can&#39;t] condemn the practice on which it’s business model depends</em></a><em>&quot;.</em> An overly permissive API they already changed years ago? That can&#39;t be the crucial part of the business model. The discussion we are having is all over the place, with the common dominator being anger at Facebook. It&#39;s rare to see someone clearly articulating what the company is actually doing wrong.</p><p>As many have discussed, the big tech companies are no longer the likable rebels they used to be. The public of course has always been distrustful of large corporations, sensibly so. And maybe as a society, we did indeed become more privacy conscious (I think that remains to be seen). Combine that with a media which more than ever is incentivized to sell, not to inform, privacy activists who want Facebook gone, no matter the details of any particular incident, and an utterly partisan political culture with a left which still hasn&#39;t come to terms with the fact that their fellow citizens indeed voted for Trump and Brexit, then here is where we end up.</p><p>All of that wouldn&#39;t matter so much, except I am concerned what an effect this could have on Facebook&#39;s openness to developers, and indeed the wider landscape. While I was writing this, Facebook <a href="https://news.ycombinator.com/item?id=16701913#16702489">paused app reviews, disabled user authorization in some cases, and announced they will review their platform</a>. Keep that in mind going forward.</p><p>So supposedly, the original sin here is that Facebook&#39;s API (which allows developers all over the world to access your data on Facebook if you give permission), was also giving out certain data about your friends, specifically, your friends&#39; likes and the simple fact that you two <em>are </em>friends — friends who themselves never gave consent that this information can be passed to this particular app. Mind you, the problem is not that Facebook has a huge amount of this data in the first place, or that their business model is targeting you with ads based on that data. Neither are we talking about the fact that they want to convince people to give them ever more data, or that we are worried that all of this data in one hand, combined with sophisticated algorithms, can be used to manipulate us. All that may all be true and worthy of discussion, but it&#39;s not new, and it won&#39;t disappear with the news cycle. No, there is a <em>whistleblower</em>, and there is a <em>breach, </em>and if there is any way at all to make that term applicable here, it&#39;s the non-consenting friends whose data has been breached. And regarding this aspect in particular, I find the way Facebook is supposed to be a bad guy here incredibly disingenuous.</p><p>Let&#39;s remember why there is a Facebook API in the first place. <em>We used to like APIs</em>. We talked about APIs in terms of <a href="http://www.computerweekly.com/feature/APIs-lead-the-way-to-better-interoperability">interoperability</a>, openness, data ownership. The p<a href="https://www.programmableweb.com/">rogrammable web</a>. <a href="https://ifttt.com/">IIFT</a>. We convinced companies to add APIs by telling them &quot;this will be good for your business and for the open web&quot;, and today, you’ll be hard pressed to find a self-respective web service that doesn’t have an API. When Mark Zuckerberg launched the &quot;Facebook Platform&quot; a decade ago, TechCrunch wrote excitedly <em>&quot;Facebook is giving an unprecedented amount of access to developers. The API would allow, for example, a third party to recreate Facebook Photos&quot;</em>. It then goes on to complain about how old-fashioned MySpace is, trying to control third party widgets.</p><p>Was it wrong for Facebook to expose the friend data through the API in the way that they did? They certainly seemed to think so, which is why they changed it in 2014. Was it an obviously crazy idea to do so? Well, not if you imagine developers to be able to do things like recreate Facebook Photos.</p><p>Which is why hundreds of thousands of people read and worked with the API, creating millions of apps, and no one blinked twice about this allegedly dangerous issue. Including, yes, the good people of the Obama campaign. All those people missed the evil right in front of their eyes, it seems. And when Facebook finally did decide to change the API, they calmly phased out the old version over a period of a year, because that is what you are supposed to do as a responsible platform who is dealing with an elective, non-security-related API change.</p><p>It is just completely disingenuous to claim, as <a href="https://www.theguardian.com/technology/2018/mar/24/cambridge-analytica-week-that-shattered-facebook-privacy">Jeff Hauser does here in the Guardian</a> that <em>“Now [Facebook] are complaining that the developers abused them. They wanted that. They were encouraging it”</em>. Sure they did, and developers themselves wanted it. The tech industry as a whole encouraged it. Open platforms and APIs, at least for a sizable chunk of us, was a deeply ingrained part of our philosophy.</p><p>Jonathan Albright says Facebook offers <a href="https://medium.com/tow-center/the-graph-api-key-points-in-the-facebook-and-cambridge-analytica-debacle-b69fe692d747">industrial-level personal data access to researchers and businesses</a>. Phrasing it like that is I think bordering on dishonest. Facebook offers an API that is <strong>open to everyone</strong>. That is the whole point. If data access was restricted to select business partners, we might well not be here right now. It is precisely because Facebook does not ask for a phone call, or a business plan review, that there are <a href="http://www.adweek.com/digital/facebook-platform-supports-more-than-42-million-pages-and-9-million-apps/">millions of apps</a> instead of hundreds. Because otherwise small and independent developers wouldn’t have access. We’d be missing out on all that good stuff that openness brings. At least, that used to be the idea.</p><p>So yes, this has everything to do with Facebook as an open platform. The ideal of a Facebook API that is powerful and has a low barrier to entry is in tension with the notion (and possible fact) that users cannot be trusted to handle their own data responsibly.</p><p>Facebook always had terms of services that forbade data collection. Facebook already does reviews of apps. Facebook is already limiting the data that can be accessed via the API. Facebook is in fact trying to protect against data scraping. You can ask them to do more reviews and checks, but at some point, it simply isn&#39;t economical to let every rando create apps on your platform. And that point arrives rather sooner for Facebook than it does for Apple&#39;s AppStore, because Facebook does not host the apps themselves.</p><p>Do we really think that the scandal would be substantially smaller if the data collected and used by Cambridge Analytica did only come from users that authorized the app, and did not include their friends? Do you get the feeling that the media care about this distinction?</p><p>From a technical perspective, what happened with Cambridge Analytica is actually quite similar to something that is happening every day: On Android, apps can ask people for access to their phone book. Lots of social networks do this (the &quot;find your friends on here&quot; feature). Because your friends are clicking yes, these sites now have your information. It&#39;s actually worse than the Facebook situation: They can get access to your phone number, email address and more in this way. A lot of people clicked yes on that button. You probably clicked yes. And your friends have never consented.</p><p>A court in Germany recently decided that <a href="https://www.stern.de/digital/smartphones/whatsapp-gerichtsurteil--abmahnung-moeglich--wenn-man-kontakte-weitergibt-7519552.html"><em>you </em>are liable for that privacy violation</a>. I think that&#39;s interesting, because it is essentially saying, you can&#39;t just claim users are uninformed, don&#39;t read terms or always click yes. It&#39;s the exact opposite philosophy of what <a href="https://twitter.com/tomwarren/status/977640920186343424">the editor of The Verge</a> believes, when he castigates Google for offering that kind of API access in the first place.</p><p>And that is what I am worried about. Next they might come for Android. Android already had it&#39;s fair share of minor scandals with bad apps. But so far, we kind of accepted that this is the price you have to pay for a platform that let&#39;s you do fun things like replace the Dialer app, install a third party app store, or the whole home screen. You can&#39;t do any of that on iOS. Apple doesn&#39;t give that kind of access. Which means users are protected from all sorts of bad decisions.</p><p>Twitter. Twitter is essentially a huge database of people-relationships and people-likes, exactly the data taken from Facebook. Except on Twitter, this data is basically all public already (with the exception of the very small number of private profiles). Even without an API, it can simply be scraped. I wonder what can be gained from analyzing the likes of millions of Twitter users. I&#39;m sure it&#39;s suitable to be weaponized as a <a href="https://www.theguardian.com/news/2018/mar/17/data-war-whistleblower-christopher-wylie-faceook-nix-bannon-trump">psychological warfare tool</a>. Someone probably already did it. It&#39;s a data breach scandal just waiting for a flashy whistleblower or loath-worthy antagonist.</p><p>Ultimately, if you can convince millions of people to share their data with you, you will have a lot of data. And if a lot of people&#39;s data is one place, and that place allows people to share their data with you easily, your job of convincing them just got easier. I know a lot of people don&#39;t like this. It&#39;s a fair thing to worry about.</p><p>But I think you will find that Facebook, Twitter et. al. do not in fact depend very much on their platforms being super-open. They can always make deals with Farmville or Candy Crush. But if we want access to be available to developers of all sizes, we have to hold those to account who would seek to disinform and scandalize, make a case for the benefits of this kind of openness, and encourage an informed debate. Making Facebook out to be a malicious actor, or exaggerating the impact and extend of what happened is anything but.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d060ceb0f7e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Portals can take you anywhere]]></title>
            <link>https://medium.com/@elsdoerfer/react-portals-can-take-you-anywhere-1027c346a127?source=rss-1a2658cd8a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/1027c346a127</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[elsdoerfer]]></dc:creator>
            <pubDate>Wed, 18 Oct 2017 20:03:26 GMT</pubDate>
            <atom:updated>2017-10-18T20:03:26.067Z</atom:updated>
            <content:encoded><![CDATA[<p>Most heavy React users will have heard about unstable_renderSubtreeIntoContainer and friends. You&#39;d use it to create modals or tooltips. Recently React started supporting it officially with the <a href="https://reactjs.org/docs/portals.html">Portals AP</a>I, but everything in this article applies to either version.</p><p>When you are creating portals, you are probably attaching them all to document.body. Myself, Inever really thought about doing something else, and never needed to. But to satisfy our curiosity, what happens if we target a DOM node that is already managed by React? <a href="https://codesandbox.io/s/q76k425kzw">Turns out that works just fine!</a></p><p>So recently this happened:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F238831063&amp;dntp=1&amp;url=https%3A%2F%2Fvimeo.com%2F238831063&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F661633661_1280.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=vimeo" width="1444" height="1440" frameborder="0" scrolling="no"><a href="https://medium.com/media/9aea1b613b6f7d3f0ab78653fc90b31d/href">https://medium.com/media/9aea1b613b6f7d3f0ab78653fc90b31d/href</a></iframe><p>As you can see, the page change animation and the portal bite each other. Because the dialog itself is attached to document.body, separate from the rest of the React app, it will not be affected by the transition animation. It only disappears at the end, when the old page component has been faded out and is finally unmounted.</p><p>Let&#39;s take a quick step back. How do modals work? Deep inside the React component tree there is the delete button, and we want it to show a modal dialog. The React component representing this modal is a sibling of the button. We position the modal &lt;div&gt;on top of the whole screen with position: absolute. In theory, that modal &lt;div&gt; can be anywhere within DOM, but in practice, there are overflow and position: relative issues, and you need to attach it towards the top of the tree. Thus portals and document.body.</p><p>The tree structure is something like this:</p><pre>&lt;body&gt;<br>   &lt;Portal&gt;<br>       &lt;ActualModal&gt;<br>   &lt;AppRoot&gt;<br>       &lt;Router&gt;<br>          &lt;Transition&gt;<br>              &lt;Page previous&gt;<br>                   &lt;Button&gt;<br>                   &lt;Modal&gt;<br>              &lt;Page next&gt;</pre><p>Any proper fix is going to revolve around rendering &lt;ActualModal&gt; as part of their respective page component. But the idea of somehow telling &lt;Page&gt; which modals to render, and then having the page component manage the visible modals always seemed a bit messy to me.</p><p>But given what we learned about the capabilities of React portals, there is an easy solution. We don&#39;t have to worry about telling &lt;Page&gt; to handle our modals. We can just have each modal render itself in the top most parent!</p><pre>class PortalRoot extends Component {<br>  static childContextTypes = {<br>    portalRoot: PropTypes.object<br>  };</pre><pre>  getChildContext() {<br>    return {<br>      portalRoot: this<br>    }<br>  }</pre><pre>  render() {<br>    return React.Children.only(this.props.children);<br>  }<br>}</pre><p>And then:</p><pre>static contexTypes = {<br>  portalRoot: PropTypes.object<br>};</pre><pre>render() {<br>  return createPortal(<br>    &lt;Modal /&gt;,<br>    this.context.portalRoot<br>  );<br>}</pre><p>And now it works as expected.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1027c346a127" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Good React Modals]]></title>
            <link>https://medium.com/@elsdoerfer/good-react-modals-548cd9c2f7f4?source=rss-1a2658cd8a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/548cd9c2f7f4</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[elsdoerfer]]></dc:creator>
            <pubDate>Sat, 02 Sep 2017 13:58:16 GMT</pubDate>
            <atom:updated>2017-09-02T13:58:16.173Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TiWlGUMXjTRntsahEA8OUA.jpeg" /><figcaption>A Modal Dialog.</figcaption></figure><p>This is not about a new modal library. Instead, I&#39;d like to talk about about some specific issues I struggled with over the two years or so I have been using React, and the approach I ultimately settled on.</p><p>What kind of issues? There are two we will discuss: Not rendering a modal content while it is invisible while doing proper fade-out animations and managing , and side-loading data for the modal while having a proper loading indicator.</p><p>Let&#39;s first have a look at a simple modal such you might write when you first pull a library like <a href="https://github.com/reactjs/react-modal">react-modal</a> into your project:</p><pre>function PickGroupDialog(props) {<br>  const {isOpen, onRequestClose} = props;<br>  return &lt;Modal isOpen={isOpen} onRequestClose={onRequestClose}&gt;<br>     &lt;select /&gt;<br>  &lt;/Modal&gt;<br>}</pre><pre>class Screen extends Component {</pre><pre>  state = {<br>    dialogIsOpen: false<br>  }</pre><pre>  render() {<br>    return &lt;div&gt;<br>      &lt;PickGroupDialog<br>        isOpen={this.state.dialogIsOpen}<br>        onRequestClose={this.handleDialogClose}<br>      /&gt;<br>      &lt;button onClick={this.handleDialogOpen}&gt;Edit&lt;/button&gt;<br>    &lt;/div&gt;<br>  }</pre><pre>  handleDialogOpen = () =&gt; {<br>    this.setState({dialogIsOpen: true});<br>  }</pre><pre>  handleDialogClose = () =&gt; {<br>    this.setState({dialogIsOpen: false});<br>  }<br>}</pre><p>Apart from being verbose, this works pretty well at first, but I quickly find myself trying to solve these problems:</p><ol><li>The modal contents are rendered even if the dialog is closed. One of the reasons this is problematic is because to render the content, you might be accessing properties that are not yet set by the owner.</li><li>It&#39;s difficult to side-load data for the modal if you want to show a proper loading indicator.</li><li>(Also, did I mention how painfully verbose it is?)</li></ol><p>To see these issues in action, let&#39;s extend the code above a little bit.</p><pre>function PickGroupDialog(props) {<br>  const {isOpen, onRequestClose, user, groups} = props;<br>  return &lt;Modal isOpen={isOpen} onRequestClose={onRequestClose}&gt;<br>     Pick group for user: {user.name}<br>     &lt;Select items={groups} /&gt;<br>  &lt;/Modal&gt;<br>}<br>PickGroupDialog = loadGroups()(PickGroupDialog);</pre><pre>class Screen extends Component {<br>  state = {<br>     selectedUser: null<br>  }<br>  render() {<br>    return &lt;div&gt;<br>      &lt;PickGroupDialog<br>        isOpen={!!this.state.selectedUser}<br>        onRequestClose={this.handleDialogClose}<br>        user={this.state.selectedUser}<br>      /&gt;<br>      {Users.map(user =&gt; &lt;li&gt;<br>        &lt;button onClick={() =&gt; this.setState({selectedUser: user}) }&gt;Edit {user.name}&lt;/button&gt;<br>      &lt;/li&gt;)}<br>    &lt;/div&gt;<br>  }<br>}</pre><p>We are now passing a <em>user </em>object to the dialog. We are also wrapping the modal with a data loader. This code as a couple of problems:</p><ol><li>It will actually crash, because on the initial render, Screen.state.selectedUer isnull, but the dialog&#39;s render function still runs, and tries to access the users .name property.</li><li>While loadGroups is loading data from the server, we don&#39;t show a loading indicator in the UI. The normal way a data-loading HoC might show an indicator — rendering it instead of the children — doesn&#39;t work here.</li></ol><p>Let&#39;s look at these separately, and discuss potential solutions:</p><p><strong>1 — The modal content renders even when the modal is invisible.</strong></p><p>So, in the example above, we could just check if theuser property has been passed, and accommodate for the case that it&#39;s not. That will get old soon if you have a bunch of these properties.</p><p>A version of this idea is to just hide the modal completely if it&#39;s not supposed to be open:</p><pre>function PickGroupDialog(props) {<br>  const {isOpen, onRequestClose} = props;<br>  if (!isOpen) { <br>     return null;<br>  }<br>  return &lt;Modal isOpen={isOpen} onRequestClose={onRequestClose}&gt;<br>     ....<br>  &lt;/Modal&gt;<br>}</pre><p>This kind of works, except:</p><ul><li>Does your &lt;Modal&gt; include a hide animation? This animation is now broken, because you abruptly remove the whole component from the tree.</li><li>The less invasive version, checking only if the user property is passed suffers from a less severe version of the same problem. When the dialog is closed from <em>Screen</em>, you will likely also set the user property to <em>null</em>. While the modals hide animation is running, you can sometimes see that change on the screen: elements like the username disappearing.</li><li>As a general note, let&#39;s consider that rendering a bunch of invisible dialogs for no reason has a performance impact.</li><li>There is also the issue of state. If your modal has state, you may want to reset that once the dialog is closed. If your PickGroupDialog component holds state, it won&#39;t be reset as long as PickGroupDialog remains in the component tree. You know have to manage this state reset manually via componentWillReceiveProps 🤢.</li><li>And we didn&#39;t even talk about our use of the data loading HoC. loadGroups will load the data even before the modal is ever opened.</li></ul><p><strong>2 —Showing a loading indicator for the HoC.</strong></p><p>If your modal needs to load data when it opens, and you want to show a loading indicator (you probably do), there are really three ways you can go:</p><ul><li>You show the indicator inside the modal.</li><li>You show the indicator on/next to the button that was clicked.</li><li>You show the indicator globally, maybe a NProgress-like top bar.</li></ul><p>If those, the last one is potentially the easiest, because you can implement this without considering your modal implementation. The loadGroups HoC shows above would just have to communicate up to the global progress bar during loading.</p><h4>Let&#39;s talk about solutions</h4><p>I think the way to solve this is using the <em>function-as-a-child</em> pattern. Image your modal component has an API like this:</p><pre>function PickGroupDialog(props) {<br>  const {isOpen, onRequestClose, user} = props;<br>  return &lt;Modal isOpen={isOpen} onRequestClose={onRequestClose}&gt;<br>    {<br>      () =&gt; &lt;div&gt;<br>        &lt;input value={user.name} /&gt;<br>      &lt;/div&gt;<br>    }<br>  &lt;/Modal&gt;<br>}</pre><p>This solves a couple of our problems:</p><ul><li>The content will not be rendered when the modal is not open, so you don&#39;t have to worry about theuser prop being <em>null</em>, or about performance issues.</li><li>When the modal is closed, the &lt;Modal&gt; component will extend it&#39;s existing hack and continue to render the old children, with the old props, during the out-animation.</li></ul><p>But not all of them:</p><ul><li>If PickGroupDialog holds state, it still will not be reset.</li><li>If we want to wrap PickGroupDialog inside a data-loading HoC, this HoC still has no way to render a loading indicator inside the modal.</li></ul><h4>Another attempt</h4><p>The reason we are still having these issues is that our component, PickGroupDialog sits on top of all the sweet modal magic, so the data loading and state is above the modal too. We&#39;d have to move it one level down:</p><pre>function PickGroupDialogUI(props) {<br>  const {user, groups} = props;<br>  return &lt;div&gt;<br>    Pick group for user: {user.name}<br>    &lt;Select items={groups} /&gt;<br>  &lt;/div&gt;<br>}<br>PickGroupDialogUI = loadGroups()(PickGroupDialogUI);</pre><pre>function PickGroupDialog(props) {<br>  const {isOpen, onRequestClose, ...rest} = props;<br>  return &lt;Modal isOpen={isOpen} onRequestClose={onRequestClose}&gt;<br>    {() =&gt; &lt;PickGroupDialogUI {...props}&gt;}<br>  &lt;/Modal&gt;<br>}</pre><p>Any state inside PickGroupDialogUI will now be reset if the dialog closes. If loadGroups shows a loading indicator while loading is ongoing, this will appear inside the modal.</p><p>And while it seems quite painful to separate every dialog into two components, we can create our own modal HoC:</p><pre>function PickGroupDialogUI(props) {<br>  const {user, groups} = props;<br>  return &lt;div&gt;<br>    Pick group for user: {user.name}<br>    &lt;Select items={groups} /&gt;<br>  &lt;/div&gt;<br>}<br>PickGroupDialogUI = loadGroups()(PickGroupDialogUI);</pre><pre>const PickGroupDialog = modal(PickGroupDialogUI);</pre><p>I&#39;ve been using this approach for some time now, and it&#39;s been working super well. I apologize for not posting a ready-to-use code snippet here, but if you are facing these issues, I hope that this discussion helped you with building your own solution.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=548cd9c2f7f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>