Add another HTML printing test case and handle lazy HTML nodes nested under keyed nodes.

This commit is contained in:
Dillon Kearns 2022-08-25 12:02:15 -07:00
parent 18a5d20ccf
commit abc91541e2
3 changed files with 22 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import Head
import Head.Seo as Seo import Head.Seo as Seo
import Html.Styled as Html exposing (..) import Html.Styled as Html exposing (..)
import Html.Styled.Attributes as Attr import Html.Styled.Attributes as Attr
import Html.Styled.Keyed as HtmlKeyed
import Html.Styled.Lazy as HtmlLazy import Html.Styled.Lazy as HtmlLazy
import Pages.Msg import Pages.Msg
import Pages.PageUrl exposing (PageUrl) import Pages.PageUrl exposing (PageUrl)
@ -101,5 +102,22 @@ view maybeUrl sharedModel static =
-- lazy and non-lazy versions render the same output -- lazy and non-lazy versions render the same output
, Html.text static.data , Html.text static.data
, HtmlLazy.lazy (.data >> text) static , HtmlLazy.lazy (.data >> text) static
, [ 1 ]
|> List.indexedMap
(\index _ ->
( String.fromInt index
, HtmlLazy.lazy2
(\_ _ ->
li []
[ Html.text <|
"This is number "
++ String.fromInt index
]
)
()
()
)
)
|> HtmlKeyed.ul []
] ]
} }

View File

@ -26,6 +26,6 @@
<div><style></style><label for="note"></label><div><style>div > p { <div><style></style><label for="note"></label><div><style>div > p {
font-size:14px; font-size:14px;
color:rgb(255, 0, 0); color:rgb(255, 0, 0);
}</style><div><p>Hello! 2 &gt; 1</p></div></div>&lt;script&gt;&lt;/script&gt; is unsafe in JSON unless it is escaped properly.&lt;script&gt;&lt;/script&gt; is unsafe in JSON unless it is escaped properly.</div> }</style><div><p>Hello! 2 &gt; 1</p></div></div>&lt;script&gt;&lt;/script&gt; is unsafe in JSON unless it is escaped properly.&lt;script&gt;&lt;/script&gt; is unsafe in JSON unless it is escaped properly.<ul><li><style></style>This is number 0</li></ul></div>
</body> </body>
</html> </html>

View File

@ -563,7 +563,9 @@ async function compileCliApp(options) {
} }
function forceThunks(vNode) { function forceThunks(vNode) {
if (typeof vNode !== "undefined" && ( (vNode.b && vNode.b.$ === virtualDomKernelConstants.nodeTypeThunk) || vNode.$ === "#2" )) { if ( (typeof vNode !== "undefined" && vNode.$ === "#2") // normal/debug mode
|| (typeof vNode !== "undefined" && typeof vNode.$ === "undefined" && typeof vNode.a == "string" && typeof vNode.b == "object" ) // optimize mode
) {
// This is a tuple (the kids : List (String, Html) field of a Keyed node); recurse into the right side of the tuple // This is a tuple (the kids : List (String, Html) field of a Keyed node); recurse into the right side of the tuple
vNode.b = forceThunks(vNode.b); vNode.b = forceThunks(vNode.b);
} }