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.

Don't lock render before calling view function.

See original GitHub issue

Recently I have been playing around with modules that map external state of things like mouse, scroll and location to hyperapp state. I have observed that it certain cases when update is called in rapid succession; that the data used in the last render is not the data in the state.

If I remove the skip render check (but leave rAF), the behaviour goes away:

function repaint() {
  if (props.view) { requestAnimationFrame(render) }
}

I started looking at requestAnimationFrame as I haven’t used it since I experimented with WebGL years ago. From what I can gather:

  • Requests that the browser call a specified function before the next repaint
  • You should call this method whenever you’re ready to update your view onscreen

It doesn’t say anything about skipping renders 🤔 and it makes me wonder why we are doing this? I have always thought of requestAnimationFrame as like a smart debounce/throttle which you throw whatever you want at, and it makes sure not to over compute.

Looking at the current setup it seems that a state update assign(state, data) could be made, which calls repaint() when skipRender is true meaning that render is never called. This would explain the behaviours I have witnessed.

Interestingly removing all trace of skipRender seems to have no adverse effects at all on hyperapp even when challenged with rapid state updates. Do we need it for some reason I am not remembering?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
SkaterDadcommented, Oct 20, 2017

If you could join us on slack, you’d see, it was a 2 hour long discussion with Luke.

Unfortunately my work blocks Slack, so I miss out on that sort of thing. I look forward to seeing what comes out of it, though. 👍

0reactions
SkaterDadcommented, Oct 21, 2017

@lukejacksonn I agree that last snippet looks appealing. The dynamic nature of component routes is also pretty neat.

I’m hesitant because of the way hyperapp re-runs the whole view() function on every state update. In your sample, it wouldn’t be an issue unless some other action (potentially unrelated) triggered a state update before your actions.fetchData() finished. In that case, you’ll end up calling fetchData() again.

Easy enough fix in this case, but does this approach scale up to even more complicated apps? Some ideas could be borrowed from RemoteData for elm?

div([
  !state.fetching && actions.fetchData(),
  state.fetching ? div('Fetching..') : ul(state.data.map(li))
])

I look forward to being able to play around with this approach. For now, I built a HOA routing solution that works for me (routes pre-defined and passed in up front), so I might be able to upgrade my main project from 0.12.1 at long last 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I block a React component to be rendered until I ...
The information will be provided by an API and fetched with an ajax call. I'm just trying to wait 10 seconds before rendering...
Read more >
Run Code in React Before Render - Dave Ceddia
Want to run some code before your React component renders? There are a few ways to make this work, and we'll talk about...
Read more >
Bug: useEffect runs twice on component mount (StrictMode ...
After state change the component renders twice but the effect runs once. The expected behavior. I should not see different number of renders...
Read more >
Suspense for Data Fetching (Experimental) - React
We call this approach “fetch-on-render” because it doesn't start fetching until after the component has rendered on the screen. This leads to a...
Read more >
React Hooks cheat sheet: Best practices with examples
React useState and setState don't make changes directly to the state ... Multiple useEffect calls can happen within a functional component, ...
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