question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] reloadClientData() does not reload site data

See original GitHub issue

Short 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

  1. Create new project using react-static v7.0.5 using blank template.
  2. Add data/site.yaml with following contents to the project:
title: My Site!
  1. You will need to install node-watch and js-yaml for the next step:
$ yarn add node-watch js-yaml
  1. 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 {}
    }
  }
}
  1. 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
  1. Start development server
  2. 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 for getSiteData().

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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
Blobsoncommented, Aug 11, 2019

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.

1reaction
Blobsoncommented, Aug 11, 2019

Try editing version inside node_modules/react-static/… Unfortunately, I can’t check it myself because I am away from my PC.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found