browser icon indicating copy to clipboard operation
browser copied to clipboard

Why can't Browser.application have an element mount point?

Open toastal opened this issue 5 years ago • 6 comments

Right now Browser.application wipes clean the <body>. The body can be used as a place for useful stuff to exst. For us, it was a) scripts to not be in the head, and b) inlining our SVG icons.

Inlining the SVG icons previous allowed us:

  1. one less network request for a required resource
  2. IE11 support
  3. no flash of content for getting the #id from a <use> tag
  4. Not having to deal with hashing/asset management as NRI's Webpack asset plugin does not support v0.19.

The v0.18 did not clear the body. Clearing the element is fine and whatever, but since the body of document still serves as a storage space for other content, there shouldn't be anything wrong with mounting at <body><div id="app"></div>... OTHER STUFF...</body>. Sure, the application would now have to measure different elements than the body, but what's wrong with that?

toastal avatar Feb 18 '19 08:02 toastal

Related https://discourse.elm-lang.org/t/fullscreen-elm-app-in-0-19-childnode-issue-reopened/3174

albertdahlin avatar Feb 20 '19 05:02 albertdahlin

Q: We are using Browser.application and inline svg-icons in the body which works fine. Though they are inserted there build-time. Are you doing it with some "webpack magic"?

mikaxyz avatar Feb 23 '19 18:02 mikaxyz

Rails, but it could be Webpack, gulp, whatever. It's not uncommon to do this.

toastal avatar Feb 25 '19 10:02 toastal

Made some tests and realised why it works for us is that we have the icons rendered after Elm.Main.init() in body. Don't know the implications on this regarding best practice but at least it works and can be a workaround util other solutions. Our body-tag:

<body>
<!-- Elm -->
<script src="/app.js"></script>
<script>
	var app = Elm.Main.init();
</script>
<!-- icons -->
<div style="display: none;">
	<svg xmlns="http://www.w3.org/2000/svg">
		<symbol viewBox="0 0 41 66" id="icon-pmt-logo"><title>pmt-logo</title>
			<!-- svg icon -->
		</symbol>
	</svg>
</div>
</body>

mikaxyz avatar Feb 25 '19 10:02 mikaxyz

This is not ideal for us, we use Google Sign-In for all of our internal apps and this works by creating a hidden iframe, when Browser.application wipes the <body> clean it breaks our authentication.

Also, if the Elm.Main.init({node: ... }) parameter is going to be ignored I'd expect to see a warning about this in the console.

ianp avatar Apr 02 '19 16:04 ianp

😢 It breaks my Vim-like browser extension too.

toastal avatar Apr 02 '19 16:04 toastal