[Bug] reloadClientData() does not reload site data
See original GitHub issueShort description I am using site.yaml file to store site data and in development mode I want to hot-reload site data on every change in site.yaml.
Steps to reproduce the issue
- Create new project using react-static v7.0.5 using blank template.
- Add data/site.yaml with following contents to the project:
title: My Site!
- You will need to install node-watch and js-yaml for the next step:
$ yarn add node-watch js-yaml
- Add getSiteData and a watcher for data/site.yaml inside static.config.js like this:
import fs from 'fs'
import path from 'path'
import yaml from 'js-yaml'
import watch from 'node-watch'
import { reloadClientData } from 'react-static/node'
const dataDir = path.join(__dirname, 'data')
watch(dataDir, { recursive: true, filter: /\.(?:yaml|yml)$/ }, (evt, name) => {
console.log(`Detected changes in '${name}', reloading client data...`)
reloadClientData()
})
export default {
maxThreads: 1, // Remove this when you start doing any static generation
getSiteData: () => {
try {
const rawSiteData = fs.readFileSync(path.join(dataDir, 'site.yaml'))
const yamlSiteData = yaml.safeLoad(rawSiteData)
console.log('SiteData: ', yamlSiteData)
return yamlSiteData
} catch(e) {
console.error(e)
return {}
}
}
}
- Add use of
const { title } = useSiteData()
to the src/App.js component like this:
import React, { Suspense } from 'react'
import { useSiteData } from 'react-static'
import './app.css'
import logo from './logo.png'
const Title = () => {
const { title } = useSiteData()
return (
<h1>{title}</h1>
)
}
const App = () => (
<Suspense fallback="Loading...">
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<Title />
</header>
</div>
</Suspense>
)
export default App
- Start development server
- Try editing title in data/site.yaml and you’ll see that changes does not hot-reload.
Also in the stdout of dev server you’ll see that
reloadClientData()
is called but it does not trigger call forgetSiteData()
.
Solution that worked for me For now the only solution that worked for me is to add:
latestState = await fetchSiteData(latestState)
inside reloadClientData()
inside runDevServer.js here.
The only downside is that now getSiteData()
is called twice at the start of development server.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:12 (9 by maintainers)
Top Results From Across the Web
UITableView reloadData does not reload - Stack Overflow
Found another problem. After saving the data and going back to the tableview when trying to scroll it shows only white cells.. it...
Read more >[Bug]: Live Reload not working. · Issue #1601 · remix-run/remix
I just did a brief experiment and moving a component into the app/ directory seems to fix it — i.e. causes changes to...
Read more >Form elements don't reset upon manually reloading page
I'm a little confused as how this should behave. In 4.x, if you go to the main bugzilla page and enter a bug...
Read more >1004038 - Refresh while on a breakpoint devtools will remain ...
Refresh should cause the browser to exit the breakpoint and reload the page immediately, like it used to do. What went wrong?
Read more >After some time site is not loading from first time only after ...
Many times, the first load didn't show images. Refreshing is showing all data well. There is no error recorded either in server error...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
As I remember Tenner had reworked the code a bit. I can take a closer look at it after I return from vacation on 18th of august.
Try editing version inside node_modules/react-static/… Unfortunately, I can’t check it myself because I am away from my PC.