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

SitecoreContextReactContext.Provider is not working properly, because value never changes as it is always same class instance #299

Closed
M1r1k opened this issue Dec 15, 2019 · 1 comment
Assignees

Comments

@M1r1k
Copy link

M1r1k commented Dec 15, 2019

Description

SitecoreContext class provide sitecore context via <SitecoreContextReactContext.Provider value={this.contextFactory}> but as suggested in samples implementation is Singleton, default React's Object.is() comparison is not working when SitecoreContextFactory.setSitecoreContext is called and Provider's children are not rerendered.

Expected behavior

All consumers be updated if context value is modified

Steps To Reproduce

  1. Start ./samples/react and go to http://localhost:3000/styleguide/custom-route-type for example.
  2. Add this line to ./src/AppRoot.js - window.debug1 = SitecoreContextFactory; - for debugging purpose later
  3. Now on "Custom route type" page we can trigger setSitecoreContext from the console
  4. Run this code
debug1.context.route.fields.headline.value = "Reproduced"
debug1.setSitecoreContext(debug1.context)

This has to update headline property's value that should effect our page's tittle. But it does not.
However if you change <SitecoreContextReactContext.Provider value={this.contextFactory}> to
<SitecoreContextReactContext.Provider value={Object.assign( Object.create( Object.getPrototypeOf(this.contextFactory)), this.contextFactory)}> it will work fine.

Possible Fix

We have to use React best practice and pass simple objects to Provider value, like this.contextFactory.context

Your Environment

  • JSS Version: 13.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants