Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Container create context issues after Babel 7.9.x update. #489

Closed
pmysinski opened this issue Jun 4, 2020 · 5 comments
Closed

Container create context issues after Babel 7.9.x update. #489

pmysinski opened this issue Jun 4, 2020 · 5 comments

Comments

@pmysinski
Copy link

pmysinski commented Jun 4, 2020

After Babel 7.9.x Update exactly @babel/preset-env -> @babel/plugin-transform-classes

We have issue with proper context in Container components.
Constructor has different context than render function.
Until the update similar code to this one had been working properly (v7.8.6), we could bind functions in constructor and pass them to children components as props.

Example reproduction:

import React from 'react';
import FluxUtils from 'flux/utils';
import { Dispatcher } from 'flux';

class Store extends FluxUtils.ReduceStore {
  constructor() { super(new Dispatcher()); }
  getInitialState() { return {}; }
  reduce(state) { return state; }
}

const store = new Store();
let self;
class Component extends React.Component {

  static getStores() { return [store] }
  static calculateState() { }

  constructor() {
    super();
    this.foo = this.foo.bind(this);
    self = this;
  }

  foo() {
    console.log(this === self); 
  }

  render() {
    console.log(this === self); // false 
    this.foo() // false
    const obj = Object.assign({}, {foo: this.foo })
    obj.foo(); // foo is not binded so will be called with obj context so print false
    return (
      <p> hello</p>
    );
  }
}

export default FluxUtils.Container.create(Component);

Babel:

  presets: [
    [
      '@babel/preset-env',
      {
        useBuiltIns: 'entry',
        corejs: '3.6'
      }
    ]
  ]

package.json

...
    "@babel/preset-env": "7.9.0",
    "@babel/preset-react": "7.9.0",
...

I'm not sure whos issue this is babel or flux but it would nice to have this back to work how it used to:)

@kyldvs
Copy link
Contributor

kyldvs commented Jun 4, 2020

Thanks for the report! I've switched teams and haven't worked on Flux in quite a while, if anyone is able to help debug this and submit a PR that would be great. I will be able to merge it and do a release. If not this may be a bit slower to get resolved.

@rvignacio
Copy link

Had the same error, seems to be caused by the older Babel version used to generate the dist files for this repo. I updated my build to have current Babel transpile the source files and my app works again.

@koba04
Copy link
Contributor

koba04 commented Aug 5, 2020

@pmysinski @rvignacio
I've updated Babel to the latest version and published it as @koba04/flux temporally.
#495
It would be helpful for me if you would test the pacakge whther it works fine or not.

@rvignacio
Copy link

@koba04 I confirm your fix works, thank you!

@pmysinski
Copy link
Author

it works.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants