@joystick.js/node-canary 0.0.0-canary.368 → 0.0.0-canary.369

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- var i=null,c=0,a=(e={},t=null)=>{let n=new WebSocket(`ws://localhost:${window.__joystick_hmr_port__}/_joystick/hmr?${new URLSearchParams(e.query).toString()}`);i&&(clearInterval(i),i=null);let _={client:n,send:(o={})=>(e.queryParams&&(o={...o,...e.queryParams}),n.send(JSON.stringify(o)))};return n.addEventListener("open",()=>{console.log("[hmr] Listening for changes..."),c=0,t&&t(_)}),n.addEventListener("message",o=>{o?.data&&e.onMessage&&e.onMessage(JSON.parse(o.data),_)}),n.addEventListener("close",()=>{console.log("[hmr] Disconnected from server."),n=null,e.autoReconnect&&!i&&(i=setInterval(()=>{n=null,c<12?(a(e,t),console.log(`[hmr] Attempting to reconnect (${c+1}/12)...`),c+=1):(console.log("[hmr] Reconnection attempts exhausted. Server is unavailable."),clearInterval(i))},5e3))}),_},d=async()=>{let e=await l();window.joystick.mount(e,Object.assign({},window.__joystick_ssr_props__),document.getElementById("app"))},l=async()=>(await import(`${window.__joystick_page_url__}?v=${new Date().getTime()}`).catch(t=>{location.reload()}))?.default,u=async()=>(await import(`${window.__joystick_layout_url__}?v=${new Date().getTime()}`).catch(t=>{location.reload()}))?.default,p=async()=>{let e=await u(),t=await l();window.joystick.mount(e,Object.assign({page:t},window.__joystick_ssr_props__),document.getElementById("app"))},w=e=>{let t=document.createElement("link");t.setAttribute("rel","stylesheet"),t.setAttribute("href","/_joystick/index.css"),document.head.replaceChild(t,e)},y=(e={})=>{let t=document.createElement("script");t.setAttribute("type","text/javascript"),t.setAttribute("src","/_joystick/index.client.js"),e.parentNode.replaceChild(t,e)},g=a({autoReconnect:!0,query:{user_language:window?.__joystick_user__?.language||"",browser_language:navigator?.language||"",page_component_path:window.__joystick_page_url__?.replace("/_joystick/","")},onMessage:async(e={},t={})=>{window.__joystick_hmr_update__=!0,window.__joystick_hmr_previous_tree__=[...window.joystick._internal.tree||[]],window.__joystick_hmr_previous_websockets__=[...window.joystick._internal.websockets||[]];let n=Object.assign({},{scrollTop:window.scrollY}),_=e&&e.type&&e.type==="FILE_CHANGE",o=!!window.__joystick_layout_url__&&!!window.__joystick_page_url__,s=document.head.querySelector('link[href="/_joystick/index.css"]'),r=document.body.querySelector('script[src="/_joystick/index.client.js"]');e?.index_html_changed&&location.reload(),e?.i18n&&(window.__joystick_i18n__=e?.i18n),e?.settings&&(window.__joystick_settings__=e?.settings,window.joystick.settings=e?.settings),r&&e?.index_client_changed&&y(r),s&&e?.index_css_changed&&w(s),_&&o&&p(t),_&&!o&&d(t),window.scrollTo(0,n.scrollTop),t.send&&t.send({type:"HMR_UPDATE_COMPLETE"})}}),m=g;export{m as default};
1
+ var i=null,c=0,l=(t={},e=null)=>{let o=new WebSocket(`ws://localhost:${window.__joystick_hmr_port__}/_joystick/hmr?${new URLSearchParams(t.query).toString()}`);i&&(clearInterval(i),i=null);let _={client:o,send:(n={})=>(t.queryParams&&(n={...n,...t.queryParams}),o.send(JSON.stringify(n)))};return o.addEventListener("open",()=>{console.log("[hmr] Listening for changes..."),c=0,e&&e(_)}),o.addEventListener("message",n=>{n?.data&&t.onMessage&&t.onMessage(JSON.parse(n.data),_)}),o.addEventListener("close",()=>{console.log("[hmr] Disconnected from server."),o=null,t.autoReconnect&&!i&&(i=setInterval(()=>{o=null,c<12?(l(t,e),console.log(`[hmr] Attempting to reconnect (${c+1}/12)...`),c+=1):(console.log("[hmr] Reconnection attempts exhausted. Server is unavailable."),clearInterval(i))},5e3))}),_},u=async()=>{let t=await d();window.joystick.mount(t,Object.assign({},window.__joystick_ssr_props__),document.getElementById("app"))},d=async()=>(await import(`${window.__joystick_page_url__}?v=${new Date().getTime()}`).catch(e=>{location.reload()}))?.default,p=async()=>(await import(`${window.__joystick_layout_url__}?v=${new Date().getTime()}`).catch(e=>{location.reload()}))?.default,y=async()=>{let t=await p(),e=await d();window.joystick.mount(t,Object.assign({page:e},window.__joystick_ssr_props__),document.getElementById("app"))},w=t=>{let e=document.createElement("link");e.setAttribute("rel","stylesheet"),e.setAttribute("href","/_joystick/index.css"),document.head.replaceChild(e,t)},g=(t={})=>{let e=document.createElement("script");e.setAttribute("type","text/javascript"),e.setAttribute("src","/_joystick/index.client.js"),t.parentNode.replaceChild(e,t)},m=l({autoReconnect:!0,query:{user_language:window?.__joystick_user__?.language||"",browser_language:navigator?.language||"",page_component_path:window.__joystick_page_url__?.replace("/_joystick/","")},onMessage:async(t={},e={})=>{if(t&&t.type&&t.type==="BUILD_ERROR")return location.reload();window.__joystick_hmr_update__=!0,window.__joystick_hmr_previous_tree__=[...window.joystick._internal.tree||[]],window.__joystick_hmr_previous_websockets__=[...window.joystick._internal.websockets||[]];let _=Object.assign({},{scrollTop:window.scrollY}),n=t&&t.type&&t.type==="FILE_CHANGE",r=!!window.__joystick_layout_url__&&!!window.__joystick_page_url__,s=document.head.querySelector('link[href="/_joystick/index.css"]'),a=document.body.querySelector('script[src="/_joystick/index.client.js"]');t?.index_html_changed&&location.reload(),t?.i18n&&(window.__joystick_i18n__=t?.i18n),t?.settings&&(window.__joystick_settings__=t?.settings,window.joystick.settings=t?.settings),a&&t?.index_client_changed&&g(a),s&&t?.index_css_changed&&w(s),n&&r&&y(e),n&&!r&&u(e),window.scrollTo(0,_.scrollTop),e.send&&e.send({type:"HMR_UPDATE_COMPLETE"})}}),j=m;export{j as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@joystick.js/node-canary",
3
3
  "type": "module",
4
- "version": "0.0.0-canary.368",
4
+ "version": "0.0.0-canary.369",
5
5
  "description": "The Node.js framework for Joystick.",
6
6
  "main": "./dist/index.js",
7
7
  "scripts": {
@@ -136,6 +136,12 @@ const hmr_client = (() =>
136
136
  page_component_path: window.__joystick_page_url__?.replace('/_joystick/', ''),
137
137
  },
138
138
  onMessage: async (message = {}, websocket_client_connection = {}) => {
139
+ const is_build_error = message && message.type && message.type === "BUILD_ERROR";
140
+
141
+ if (is_build_error) {
142
+ return location.reload();
143
+ }
144
+
139
145
  // NOTE: Set this to disable the auto mount code in layouts/pages when
140
146
  // working in an HMR/development context.
141
147
  window.__joystick_hmr_update__ = true;