NervJS / nerv

A blazing fast React alternative, compatible with IE8 and React 16.
https://nerv.aotu.io
MIT License
5.42k stars 267 forks source link

Fix wrong context value after changing the context value #135

Closed spacemeowx2 closed 5 years ago

spacemeowx2 commented 5 years ago

I wrote this test case:


it('should pass the correct value after changing the context value', () => {
  const ctx = createContext('foo')
  let doSetState = null

  let actual
  class Children extends Component {
    render () {
      actual = this.context
      return <div>bar</div>
    }
  }

  Children.contextType = ctx
  const Provider = ctx.Provider

  class App extends Component {
    constructor () {
      super(...arguments)
      this.state = { value: 'bar' }
    }
    componentDidMount () {
      doSetState = (value) => {
        this.setState({ value })
      }
    }
    render () {
      return <Provider value={this.state.value}>
        <Children />
      </Provider>
    }
  }

  render(<App />, scratch)
  expect(actual).toEqual('bar')

  doSetState('bob')
  rerender()
  expect(actual).toEqual('bob')
})

Test result:

    Expected value to equal:
      "bob"
    Received:
      {"__context_11__": {"handlers": [], "value": "bob"}}
AngryPowman commented 5 years ago

It’s very helpful to me

Sumxx commented 5 years ago

It’s very helpful to me

yuche commented 5 years ago

thx.

ZhangJian-3ti commented 5 years ago

It's been awhile. Can we release a new patch version for this?