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

Don't wrap SFC with Stateful ProxyComponent #873

Closed
theKashey opened this issue Feb 23, 2018 · 4 comments
Closed

Don't wrap SFC with Stateful ProxyComponent #873

theKashey opened this issue Feb 23, 2018 · 4 comments
Assignees

Comments

@theKashey
Copy link
Collaborator

theKashey commented Feb 23, 2018

Currently, we wrap all the functional component into the stateful ones, and this is not very cool.

  • Why do we need it? To have an instance to be used in hot-render
  • Why do we need that instance? Cos we are lazy, and want just component.render()
  • Can we stop doing it?

Actually yes - hot-replacement-render still have a code for SCF, the only part it is missing - context. As long React 15 has context as a part of react-tree, React 16 has not.

It is possible to render Components as we did it all the time, and tract the context between two Components as react-tree-walker is doing it (https://github.com/ctrlplusb/react-tree-walker/blob/master/src/index.js#L171) - just Object.assign({}, context, instance.getChildContext())

The problem - sub-render. One could not start rendering in the "middle", as long there is no way to get whole context state in a random position.
I hope some dirty hacks could provide us desired global context variable( ie this._renderer._context), but I don't know them yet.

@theKashey
Copy link
Collaborator Author

Ok. If some function does not has .contextTypes - that mean it does not has context. As result - we could continue wrapping only context-consuming SFC, keeping the normal ones unchanged.

This will make most of functional components.. functional again!

@theKashey
Copy link
Collaborator Author

I have spiked possible solution, and everything should work IF that everything had Component in the beginning.
Things become complicated if not, as long there is no way to forceUpdate SFC. There is no reaction even if one will enqueueForceUpdate manually.

In the same time - "just updated" always work, as long replace one function call by another - it's an easy task.

@theKashey
Copy link
Collaborator Author

There is an issue with implementation. Not all props got merged correctly.

@theKashey
Copy link
Collaborator Author

Fixed

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

2 participants