()
| 116 | // When in development, init a socket to listen for data changes |
| 117 | // When the data changes, we invalidate and reload all of the route data |
| 118 | function init() { |
| 119 | // In development, we need to open a socket to listen for changes to data |
| 120 | if (process.env.REACT_STATIC_ENV === 'development') { |
| 121 | const io = require('socket.io-client') |
| 122 | const run = async () => { |
| 123 | try { |
| 124 | const socket = io() |
| 125 | socket.on('connect', () => { |
| 126 | // Do nothing |
| 127 | }) |
| 128 | socket.on('message', ({ type }) => { |
| 129 | if (type === 'reloadClientData') { |
| 130 | reloadClientData() |
| 131 | } |
| 132 | }) |
| 133 | } catch (err) { |
| 134 | console.log( |
| 135 | 'React-Static data hot-loader websocket encountered the following error:' |
| 136 | ) |
| 137 | console.error(err) |
| 138 | } |
| 139 | } |
| 140 | run() |
| 141 | } |
| 142 | |
| 143 | if (process.env.REACT_STATIC_DISABLE_PRELOAD === 'false') { |
| 144 | startPreloader() |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * The preloader searches for all anchor elements on the page every poll |
no test coverage detected
searching dependent graphs…