Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Context issue #12968

Closed
zenios opened this issue Jun 2, 2018 · 2 comments
Closed

React Context issue #12968

zenios opened this issue Jun 2, 2018 · 2 comments

Comments

@zenios
Copy link

zenios commented Jun 2, 2018

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
One context consumer has a value of another contexts provider.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem:

Example

const React = require("react");
const { renderToString } = require("react-dom/server");

const {
  Provider: LocationContextProvider,
  Consumer: LocationContextConsumer
} = React.createContext("location");
const {
  Provider: BaseContextProvider,
  Consumer: BaseContextConsumer
} = React.createContext("base");

const e = React.createElement;
const html = () =>
  renderToString(
    e(
      LocationContextProvider,
      { value: "location" },
      e(BaseContextConsumer, null, baseContextValue =>
        e(LocationContextConsumer, null, locationContextValue =>
          e(
            BaseContextProvider,
            { value: "base" },
            e("span", null, `${locationContextValue} - ${baseContextValue}`)
          )
        )
      )
    )
  );

console.log("1st attempt", html());
console.log("2nd attempt", html());

Output

1st attempt <span>location - base</span>
2nd attempt <span>location - location</span>

What is the expected behavior?
1st attempt and 2nd attempt to produce the same result

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React 16.3 - 16.4
All OS
The issue does not appear on version prior react 16.3 using the create-react-context polyfill

Notes
This issue was found while trying to use Ryan's new reach/router and SSR which does something like the example above.

After communicating with him, Ryan opened the following issue on his repository.

@aweary
Copy link
Contributor

aweary commented Jun 3, 2018

Thanks for the report @zenios! I looked into this a bit and wrote up a failing test with some background here #12974.

@gaearon
Copy link
Collaborator

gaearon commented Jun 13, 2018

This is fixed in 16.4.1.

@gaearon gaearon closed this as completed Jun 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants