MCPcopy Create free account
hub / github.com/react-static/react-static / init

Function init

packages/react-static/src/browser/index.js:118–146  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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
118function 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

Callers 1

index.jsFile · 0.70

Calls 2

runFunction · 0.85
startPreloaderFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…