Skip to content

live-server injects code in HTML source view inside SVG tags #1019

Closed
@ailin10

Description

@ailin10

I am using Pattern Lab Node v3.0.1 on Linux, with Node v10, using a Gulp Edition. I am aware of the recent fix in live-server that apparently fixes it, but sadly it doesn't quite work for me.

Expected Behavior

When starting the server, patternlab should show a flawless HTML source on the Pattern Info tab.

Actual Behavior

Some strange script gets injected inside of my svg tags

    <div class="product-gallery__viewer js-product-gallery-viewer">
    </div>
    <div class="product-gallery__thumbnails mobile-hide js-product-gallery-thumbnails">
    </div>
    <div class="product-gallery__controls tablet-up-hide js-product-gallery-controls">
        <button class="gallery-control gallery-control--prev btn--reset center-vertical">
            <svg class="gallery-control__ic gallery-control__ic--prev" id="i-arrow-left-light-lrg" viewBox="0 0 100 100">
                <path d="M25.819 48.02L67.756 6.082a3.7 3.7 0 0 1 5.217 0 3.7 3.7 0 0 1 0 5.217L31.036 53.237a3.7 3.7 0 0 1-5.217 0 3.7 3.7 0 0 1 0-5.217z" class="st0"></path>
                <path d="M30.958 47.943l43.147 40.693a3.7 3.7 0 0 1 .153 5.215 3.7 3.7 0 0 1-5.215.153L25.895 53.311a3.7 3.7 0 0 1-.153-5.215 3.701 3.701 0 0 1 5.216-.153z" class="st0"></path>
            <!-- Code injected by live-server -->
<script type="text/javascript">
	// <![CDATA[  <-- For SVG support
	if ('WebSocket' in window) {
		(function() {
			function refreshCSS() {
				var sheets = [].slice.call(document.getElementsByTagName("link"));
				var head = document.getElementsByTagName("head")[0];
				for (var i = 0; i < sheets.length; ++i) {
					var elem = sheets[i];
					var rel = elem.rel;
					if (elem.href && typeof rel != "string" || rel.length == 0 || rel.toLowerCase() == "stylesheet") {
						var url = elem.href.replace(/(&|\?)_cacheOverride=\d+/, '');
						elem.href = url + (url.indexOf('?') >= 0 ? '&' : '?') + '_cacheOverride=' + (new Date().valueOf());
					}
				}
			}
			var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://';
			var address = protocol + window.location.host + window.location.pathname + '/ws';
			var socket = new WebSocket(address);
			socket.onmessage = function(msg) {
				if (msg.data == 'reload') window.location.reload();
				else if (msg.data == 'refreshcss') refreshCSS();
			};
			console.log('Live reload enabled.');
		})();
	}
	// ]]>
</script>
</svg>
        </button>
    </div>
</div>
Steps to reproduce
  • Serve PL with a component containing an SVG
  • Click on "Show Pattern info"
  • Check HTML tab => broken output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions