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.

Is this the intended behavior for {pure: false}?

See original GitHub issue

Hi guys. I’m using react-komposer with composeWithTracker and receiving fewer renders from my composer function than I would expect. Setting {pure: false} fixes the issue, only I don’t understand why because the props being sent to render are obviously not shallowly equal and should trigger a re-render each time, even without {pure: false}. I’m wondering if this is the intended behavior. Here’s some code:

import React from 'react';
import { composeWithTracker } from 'react-komposer';
import DataError from './DataError.js';
import Loading from './Loading.js';

const Composer = (props, onData) => {
  const status = Meteor.status();
  onData(null, status);
}

// a quick autorun for illustration to compare against the render below
Tracker.autorun(() => {
  const status = Meteor.status();
  console.log('autorun:', status);
});

const WebApp = (props) => {
  console.log('rendered:', props.status);
  return <div></div>;
};

export default composeWithTracker(Composer, Loading, DataError)(WebApp);

The above produces from the console:

autorun: Object {status: "connected", connected: true, retryCount: 0}
rendered: Object {status: "connected", connected: true, retryCount: 0}

> Meteor.disconnect();
autorun: Object {status: "offline", connected: false, retryCount: 0}
rendered: Object {status: "offline", connected: false, retryCount: 0}

> Meteor.reconnect();
autorun: Object {status: "connecting", connected: false, retryCount: 0}
autorun: Object {status: "connected", connected: true, retryCount: 0}
// no re-render here on 'status: connecting'
// no re-render here on 'status: connected'

If I set { pure: false } with composeWithTracker(Composer, Loading, DataError, {pure: false})(WebApp) I receive the missing re-renders, but I don’t understand why they are not occurring otherwise. The objects sent to props do not pass a shallow compare when {status: 'offline'} moves to {status: 'connecting'} etc. Am I missing something here?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
arunodacommented, Jun 27, 2016

@sahanDissanayake This is not related.

0reactions
arunodacommented, Jun 27, 2016

Hi guys, sorry for the delay. This is a bug, bug we are not responsible for this. Here you directly pass the object returned by Meteor.status().

So, what’s happen is we assign this object in the component state. When there’s a change, we compare that with the new one.

But here, Meteor update this reference object itself. So, in the shallowEqual stage, both objects are the same. (This is true, even if we did a deepEqual).

So, do this and follow this approach.

const Composer = (props, onData) => {
  const status = Meteor.status();
  // do this or clone the status object
  const data = { status: status.status };
  onData(null, data);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Force Pipe To Be Called · Issue #15041 · angular ... - GitHub
The issue is that I have to make the pipe impure and so it gets called on each change detection cycle. Expected behavior....
Read more >
Compiler warnings that are off by default - Microsoft Learn
Some warnings indicate an area where programmers often make incorrect assumptions, which may lead to unexpected or undefined behavior.
Read more >
Efficient impure pipes in Angular - Damir's Corner
By default, pipes are defined as pure so that Angular executes the pipe only when it detects a pure change to the input...
Read more >
CS 165A Discussion 1 - UCSB Computer Science
True. A pure reflex agent ignores previous percepts, so cannot obtain an optimal state estimate in a partially observable environment.
Read more >
The Sharp Bits — JAX documentation
Here are some examples of functions that are not functionally pure for which JAX behaves differently than the Python interpreter.
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