Repository: single-spa/single-spa-layout
Pull request #82 (2020-10-15 19:43:57)

Fix bug where <route> elements were omitted from server response.


Patch:
diff --git a/src/server/sendLayoutHTTPResponse.js b/src/server/sendLayoutHTTPResponse.js
index 0c93769..85b3c02 100644
--- a/src/server/sendLayoutHTTPResponse.js
+++ b/src/server/sendLayoutHTTPResponse.js
@@ -129,7 +129,7 @@ function serializeChildNodes(args) {
 
     if (!inRouterElement && isApplicationNode(node)) {
       serialize = serializeApplication;
-    } else if (isRouteNode(node)) {
+    } else if (!inRouterElement && isRouteNode(node)) {
       serialize = serializeRoute;
     } else if (isRouterContent(node)) {
       serialize = serializeRouterContent;


Test patch:
diff --git a/test/node-only/__snapshots__/sendLayoutHTTPResponse-node.test.js.snap b/test/node-only/__snapshots__/sendLayoutHTTPResponse-node.test.js.snap
index 9c47534..f73ceef 100644
--- a/test/node-only/__snapshots__/sendLayoutHTTPResponse-node.test.js.snap
+++ b/test/node-only/__snapshots__/sendLayoutHTTPResponse-node.test.js.snap
@@ -45,12 +45,14 @@ exports[`sendLayoutHTTPResponse response body allows for promises that resolve w
       <application name="header">
       </application>
       <div class="main-content">
-        <button>
-          Top level content
-        </button>
-        <application name="app1">
-        </application>
-        Some raw text
+        <route path="app1">
+          <button>
+            Top level content
+          </button>
+          <application name="app1">
+          </application>
+          Some raw text
+        </route>
       </div>
       <span>
         <footer>
@@ -109,12 +111,14 @@ exports[`sendLayoutHTTPResponse response body allows for promises to be returned
       <application name="header">
       </application>
       <div class="main-content">
-        <button>
-          Top level content
-        </button>
-        <application name="app1">
-        </application>
-        Some raw text
+        <route path="app1">
+          <button>
+            Top level content
+          </button>
+          <application name="app1">
+          </application>
+          Some raw text
+        </route>
       </div>
       <span>
         <footer>
@@ -173,12 +177,14 @@ exports[`sendLayoutHTTPResponse response body allows for strings to be returned
       <application name="header">
       </application>
       <div class="main-content">
-        <button>
-          Top level content
-        </button>
-        <application name="app1">
-        </application>
-        Some raw text
+        <route path="app1">
+          <button>
+            Top level content
+          </button>
+          <application name="app1">
+          </application>
+          Some raw text
+        </route>
       </div>
       <span>
         <footer>
@@ -249,12 +255,14 @@ exports[`sendLayoutHTTPResponse response body allows for strings to be returned
       <application name="header">
       </application>
       <div class="main-content">
-        <button>
-          Top level content
-        </button>
-        <application name="app1">
-        </application>
-        Some raw text
+        <route path="app1">
+          <button>
+            Top level content
+          </button>
+          <application name="app1">
+          </application>
+          Some raw text
+        </route>
       </div>
       <span>
         <footer>
@@ -313,12 +321,14 @@ exports[`sendLayoutHTTPResponse response body dom-elements.html fixture renders
       <application name="header">
       </application>
       <div class="main-content">
-        <button>
-          Top level content
-        </button>
-        <application name="app1">
-        </application>
-        Some raw text
+        <route path="app1">
+          <button>
+            Top level content
+          </button>
+          <application name="app1">
+          </application>
+          Some raw text
+        </route>
       </div>
       <span>
         <footer>
@@ -559,12 +569,14 @@ exports[`sendLayoutHTTPResponse response body renders an empty string when rende
       <application name="header">
       </application>
       <div class="main-content">
-        <button>
-          Top level content
-        </button>
-        <application name="app1">
-        </application>
-        Some raw text
+        <route path="app1">
+          <button>
+            Top level content
+          </button>
+          <application name="app1">
+          </application>
+          Some raw text
+        </route>
       </div>
       <span>
         <footer>
@@ -617,12 +629,14 @@ exports[`sendLayoutHTTPResponse response body renders an empty string when retur
       <application name="header">
       </application>
       <div class="main-content">
-        <button>
-          Top level content
-        </button>
-        <application name="app1">
-        </application>
-        Some raw text
+        <route path="app1">
+          <button>
+            Top level content
+          </button>
+          <application name="app1">
+          </application>
+          Some raw text
+        </route>
       </div>
       <span>
         <footer>
@@ -693,12 +707,14 @@ exports[`sendLayoutHTTPResponse response body renders assets and content in corr
       <application name="header">
       </application>
       <div class="main-content">
-        <button>
-          Top level content
-        </button>
-        <application name="app1">
-        </application>
-        Some raw text
+        <route path="app1">
+          <button>
+            Top level content
+          </button>
+          <application name="app1">
+          </application>
+          Some raw text
+        </route>
       </div>
       <span>
         <footer>