@@ -24,8 +24,11 @@ <h1>Python Friendly Error Messages - Demo</h1>
2424 < script type ="module ">
2525 import { examples } from './demo-examples.js' ;
2626
27+ const localHosts = new Set ( [ 'localhost' , '127.0.0.1' , '::1' ] ) ;
28+ const isLocalDevelopment = window . location . protocol === 'file:' || localHosts . has ( window . location . hostname ) ;
29+
2730 const pageParams = new URLSearchParams ( window . location . search ) ;
28- const useLocal = pageParams . has ( 'local' ) ;
31+ const useLocal = isLocalDevelopment && pageParams . has ( 'local' ) ;
2932 const navigationEntry = performance . getEntriesByType ( 'navigation' ) [ 0 ] ;
3033 const isReload = navigationEntry && navigationEntry . type === 'reload' ;
3134 let cacheBust = pageParams . get ( 'cb' ) ;
@@ -46,29 +49,36 @@ <h1>Python Friendly Error Messages - Demo</h1>
4649
4750 async function initDemo ( ) {
4851 const container = document . getElementById ( 'demo-container' ) ;
52+ const sourceBar = document . getElementById ( 'source-bar' ) ;
4953
50- const switchUrl = useLocal ? 'index.html' : 'index.html?local=true' ;
51- const bar = document . querySelector ( '#source-bar .container' ) ;
52- if ( useLocal ) {
53- bar . innerHTML = `
54- <span class="demo__source-active demo__source-active--local">● local build <code>dist/</code></span>
55- <a class="demo__source-switch" href="${ switchUrl } ">switch to vendored release</a>
56- ` ;
57- } else {
58- bar . innerHTML = `
59- <span class="demo__source-active demo__source-active--vendor">● vendored release</span>
60- <a class="demo__source-switch" href="${ switchUrl } ">switch to local build</a>
61- ` ;
54+ if ( ! isLocalDevelopment ) {
55+ sourceBar . remove ( ) ;
6256 }
6357
64- const switchLink = bar . querySelector ( '.demo__source-switch' ) ;
65- if ( switchLink ) {
66- switchLink . addEventListener ( 'click' , ( event ) => {
67- event . preventDefault ( ) ;
68- const target = new URL ( switchLink . getAttribute ( 'href' ) , window . location . href ) ;
69- target . searchParams . set ( 'cb' , String ( Date . now ( ) ) ) ;
70- window . location . assign ( target . toString ( ) ) ;
71- } ) ;
58+ if ( isLocalDevelopment ) {
59+ const switchUrl = useLocal ? 'index.html' : 'index.html?local=true' ;
60+ const bar = document . querySelector ( '#source-bar .container' ) ;
61+ if ( useLocal ) {
62+ bar . innerHTML = `
63+ <span class="demo__source-active demo__source-active--local">● local build <code>dist/</code></span>
64+ <a class="demo__source-switch" href="${ switchUrl } ">switch to vendored release</a>
65+ ` ;
66+ } else {
67+ bar . innerHTML = `
68+ <span class="demo__source-active demo__source-active--vendor">● vendored release</span>
69+ <a class="demo__source-switch" href="${ switchUrl } ">switch to local build</a>
70+ ` ;
71+ }
72+
73+ const switchLink = bar . querySelector ( '.demo__source-switch' ) ;
74+ if ( switchLink ) {
75+ switchLink . addEventListener ( 'click' , ( event ) => {
76+ event . preventDefault ( ) ;
77+ const target = new URL ( switchLink . getAttribute ( 'href' ) , window . location . href ) ;
78+ target . searchParams . set ( 'cb' , String ( Date . now ( ) ) ) ;
79+ window . location . assign ( target . toString ( ) ) ;
80+ } ) ;
81+ }
7282 }
7383
7484 try {
0 commit comments