Skip to content

Bootstrap not passing proper context on SSR #14

Description

@jcampalo

With the latest react version I'm unable to make this library work, for some reason react-tree-walker is not able to keep the context of the provider.

I was able to reproduce the error inside the asyncBootstrapper.test.js:

`
import React, { Component } from 'react'
import asyncBootstrapper from '../'

const ThemeContext = React.createContext('light')

describe('asyncBootstrapper()', () => {
let values = []
let actualContext
let contextValue

class DeprecatedAPI extends Component {
asyncBootstrap() {
values.push(this.props.id)
return true
}

render() {
  return <div>{this.props.children}</div>
}

}

class NewAPI extends Component {
bootstrap() {
values.push(this.props.id)
actualContext = this.context
return true
}

render() {
  return <div>{this.props.children}</div>
}

}

const app = Foo => (
<ThemeContext.Provider value='dark'>


Test





<ThemeContext.Consumer>
{value => {
contextValue = value
return value
}}
</ThemeContext.Consumer>



</ThemeContext.Provider>
)

beforeEach(() => {
values = []
})

it('deprecated API', () =>
asyncBootstrapper(app(DeprecatedAPI)).then(() =>
expect(values).toEqual([1, 2, 4, 3]),
))

it('new API', () =>
asyncBootstrapper(app(NewAPI), null, { bespokeContext: true }).then(() => {
expect(values).toEqual([1, 2, 4, 3])
expect(actualContext).toEqual({
bespokeContext: true,
reactAsyncBootstrapperRunning: true,
})
expect(contextValue).toEqual('dark')
}))
})
`

Updating the react version to 16.6.3 you should be able to reproduce the error.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions