React-apollo: getDataFromTree visits React 16.3 context, but does not actually set the value in the context

Created on 17 Aug 2018  路  1Comment  路  Source: apollographql/react-apollo

Intended outcome:

I am storing query variables inside the React 16.3 context, and passing them to my Query component. This works as expected on the client side, but when rendering on the server side, getDataFromTree does not update the context value.

Actual outcome:

The context value is never updated, the default set at the start is used everywhere

How to reproduce the issue:

import * as React from 'react';

import { getDataFromTree } from 'react-apollo';

const TestContext = React.createContext({ test: 'defaultValueSetByHardcode' });
const TestChildren = () => {
  return (
    <TestContext.Consumer>
      {({ test }) => {
        console.log('Consume value in TestChildren', { test });
        return (<pre>{ test }</pre>);
      }}
    </TestContext.Consumer>
  );
};

const TestParent = () => {
  console.log('Rendering TestParent, providing test = valueSetByProvider ')
  return (
    <TestContext.Provider value={{ test: 'valueSetByProvider'}}>
      <TestChildren/>
    </TestContext.Provider>
  );
};

getDataFromTree(<TestParent/>, {}).then(() => {
  console.log('Getting data does not update the context');
});

Running that will log to the terminal the following lines:

Rendering TestParent, providing test = valueSetByProvider 
Consume value in TestChildren { test: 'defaultValueSetByHardcode' }
Getting data does not update the context

Version

has-reproduction

Most helpful comment

Is this really fixed? Still experiencing the same issues.

>All comments

Is this really fixed? Still experiencing the same issues.

Was this page helpful?
0 / 5 - 0 ratings