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.

Forbid lazy state return.

See original GitHub issue

Even though the following “kind” of action is frowned upon, we could go one step further and ignore state updates (as well as re-renders).

myAction(state) {
  state.prop = 1
  return state
}

The change requires we simply check if the appState === newState and return early.

/cc @naugtur @zaceno @lukejacksonn

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
jorgebucarancommented, Sep 1, 2017

@jamen Yep, we are on sync now. 😉

And my opinion about that was expressed here.

tl;dr: This is a do-it-at-your-own-risk kind of “feature”; I won’t force you to do things in a particular way (although you should), but I am not going to go “out of my way” to let you do it either (unless there’s some trivial change that allows it).

2reactions
zacenocommented, Sep 1, 2017

Oh… I get it now! Mutating state in props is unsafe because of the shallow merge. While each action gets a new state instance, the properties containing objects will not be fresh instances.

Ok, so the unsafeness of mutating deep state properties is a completely separate issue to what’s being proposed here (because it would continue being unsafe, even if we did implement this).

…even so, I’m still not sure I like this proposal because it will be difficult to debug. I’ve written that sort of inappopriate actions in many places. This sort of “silent fail” would make refactoring harder. So if we eventually do take it in, it should be after we have a dev-build which can log warnings. Or failing that, make production builds throw errors terminating and providing stack traces.

@okwolf Thanks for giving that example! I was actually aware of the object-spread operator to use in this case, but for me personally, I don’t consider it a solution as it is only a stage-3 proposal and not yet standard ecmascriot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to prevent `useLazyQuery` queries from being re ...
When using useLazyQuery , you can set nextFetchPolicy to "standby" . This will prevent the query from firing again after the first fetch....
Read more >
Find N+1 problems instantly by disabling lazy loading
Learn about the strict lazy loading setting that allows you to disable it entirely for non-production environments.
Read more >
How To Handle Async Data Loading, Lazy Loading, and Code ...
In this step, you made your app update state only when a component is mounted. You updated the useEffect Hook to track if...
Read more >
Relationship Loading Techniques
Lazy loading refers to objects are returned from a query without the related objects loaded at first. When the given collection or reference...
Read more >
Lazy loading React components - LogRocket Blog
React.lazy() takes as its argument a function that must return a promise by calling import() to load the component. The returned promise ...
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