<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hugo Bernier</title>
    <description>The latest articles on DEV Community by Hugo Bernier (@bernierh).</description>
    <link>https://dev.to/bernierh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F427988%2Febaf56d3-ce6f-4db1-b86a-2c492332499c.png</url>
      <title>DEV Community: Hugo Bernier</title>
      <link>https://dev.to/bernierh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bernierh"/>
    <language>en</language>
    <item>
      <title>Solving the “Failed to execute ‘removeChild’ on ‘Node'” error on modern SharePoint pages</title>
      <dc:creator>Hugo Bernier</dc:creator>
      <pubDate>Mon, 29 Jun 2020 15:57:36 +0000</pubDate>
      <link>https://dev.to/bernierh/solving-the-failed-to-execute-removechild-on-node-error-on-modern-sharepoint-pages-2ge</link>
      <guid>https://dev.to/bernierh/solving-the-failed-to-execute-removechild-on-node-error-on-modern-sharepoint-pages-2ge</guid>
      <description>&lt;h2&gt;
  
  
  (Or "SharePoint ignores target attributes on hyperlinks")
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I was recently working on a custom meganav SPFx solution for a client who reported that one of the links in the navigation would always produce the following error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
in t in div in div in t in CustomizedPageLayoutScrollRegion in div in article in t in t in o in t in t in t in t in t in section in div in div in t in Styledt in t in o in t in t in t
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I immediately assumed that one of the many application extensions on the page were causing the issue.&lt;/p&gt;

&lt;p&gt;Since the target of that link was a modern page, I assumed that there was something different on that page that would cause the issue.&lt;/p&gt;

&lt;p&gt;But after removing all custom extensions on the site collection where that page resided, removing all &lt;del&gt;custom&lt;/del&gt; web parts, and even starting with a blank modern page, I still got the error.&lt;/p&gt;

&lt;p&gt;I eventually solved the issue, but it was a frustrating process.&lt;/p&gt;

&lt;p&gt;In this post, I'll explain how I solved the issue.&lt;/p&gt;

&lt;p&gt;I hope it will save you from having to search like I did.&lt;/p&gt;

&lt;h2&gt;
  
  
  data-interception="off"
&lt;/h2&gt;

&lt;p&gt;When you navigate between SharePoint modern pages, there is usually a &lt;em&gt;lot&lt;/em&gt; of stuff that is repeated on each page; stuff like navigation, suite bar, headers, footers, etc.&lt;/p&gt;

&lt;p&gt;In fact, for most pages, the only thing that changes is the content area. It does not make sense for SharePoint to re-load everything on the page -- that's just a waste of valuable bandwidth.&lt;/p&gt;

&lt;p&gt;So SharePoint uses a page router to efficiently refresh only the parts of the page that change when you navigate between pages.&lt;/p&gt;

&lt;p&gt;In most cases, that's a good thing.&lt;/p&gt;

&lt;p&gt;Except when you try to do navigate between pages from a custom SPFx solution. Especially if you open your links to a new browser tab or a new browser window.&lt;/p&gt;

&lt;p&gt;The page router will cause SharePoint to ignore &lt;code&gt;target&lt;/code&gt; attributes on your hyperlinks and produce weird errors like the one I got.&lt;/p&gt;

&lt;p&gt;And the problem is: your error may be completely different from mine, making it practically impossible to find a solution to this problem.&lt;/p&gt;

&lt;p&gt;As it turns out, &lt;a href="https://docs.microsoft.com/en-us/sharepoint/dev/spfx/hyperlinking"&gt;there is an article about this on the SharePoint development documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;All you need to do is to add &lt;code&gt;data-interception='off'&lt;/code&gt; to your anchor tag to tell SharePoint &lt;em&gt;not&lt;/em&gt; to intercept your page navigation and to bypass the page router.&lt;/p&gt;

&lt;p&gt;So, instead of this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://yoursite.sharepoint.com/sites/hr/SitePages/benefits.aspx"&lt;/span&gt; &lt;span class="na"&gt;target=&lt;/span&gt;&lt;span class="s"&gt;"_blank"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Benefits&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://yoursite.sharepoint.com/sites/hr/SitePages/benefits.aspx"&lt;/span&gt; &lt;span class="na"&gt;target=&lt;/span&gt;&lt;span class="s"&gt;"_blank"&lt;/span&gt; &lt;span class="na"&gt;data-interception=&lt;/span&gt;&lt;span class="s"&gt;'off'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Benefits&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Of course, once you figure out to use &lt;code&gt;data-interception&lt;/code&gt;, you'll find that the amazing &lt;a href="https://julieturner.net/2018/08/spfx-anchor-tags-hitting-the-target/"&gt;Julie Turner&lt;/a&gt;, &lt;a href="https://www.eliostruyf.com/navigating-to-other-pages-in-sharepoint-framework-from-code/"&gt;Elio Struyf&lt;/a&gt;, and &lt;a href="https://coreyroth.com/2019/08/21/spfx-basics-opening-a-link-in-a-new-tab/"&gt;Corey Roth&lt;/a&gt; all blogged about this before.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In summary: SharePoint ignores your anchor tags' &lt;code&gt;target&lt;/code&gt; attributes because it uses a page router to make things more efficient, which causes the issue. Adding &lt;code&gt;data-interception='off'&lt;/code&gt; will tell SharePoint not to mess with how to navigate to your pages.&lt;/p&gt;

&lt;p&gt;I have never experienced this issue because I always convince my clients &lt;a href="https://www.nngroup.com/articles/the-top-ten-web-design-mistakes-of-1999"&gt;not to open hyperlinks in new tabs&lt;/a&gt;, unless the links point to non-web documents -- in which case &lt;a href="https://www.nngroup.com/articles/open-new-windows-for-pdfs/"&gt;you should use new tabs&lt;/a&gt;. Read &lt;a href="https://medium.com/the-metric/links-should-open-in-the-same-window-447da3ae59ba"&gt;this article&lt;/a&gt; if you want to know why.&lt;/p&gt;

&lt;p&gt;I have learned over the years that ultimately, it is up to the client to decide what they want to do... even if it is the wrong thing to do. My job is to give them the relevant information they need to make an educated decision -- even if I don't agree with their decision.&lt;/p&gt;

&lt;p&gt;I also learned that any time I have a problem, I should always check &lt;a href="https://julieturner.net/"&gt;Julie Turner's blog&lt;/a&gt; first because she often has the answers I'm looking for.&lt;/p&gt;

&lt;p&gt;I hope this helps?&lt;/p&gt;

&lt;h2&gt;
  
  
  Photo Credit
&lt;/h2&gt;

&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@olloweb?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Agence Olloweb&lt;/a&gt; on &lt;a href="/s/photos/magnifying-glass?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>spfx</category>
    </item>
  </channel>
</rss>
