Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Check all exports for being React components #26

Closed
gaearon opened this issue Sep 23, 2015 · 10 comments
Closed

Check all exports for being React components #26

gaearon opened this issue Sep 23, 2015 · 10 comments

Comments

@gaearon
Copy link
Owner

gaearon commented Sep 23, 2015

Currently exports are not being checked. This is, in a way, a regression from React Hot Loader which used to check every export for componentish-ness. It's hitting us really bad in some cases:

@jamiebuilds
Copy link
Collaborator

Oh man, I have no idea how to do this that isn't going to cause a mess of other problems.

@gaearon
Copy link
Owner Author

gaearon commented Dec 9, 2015

What kind of problems? This is exactly how React Hot Loader currently works, and it's pretty stable.

@jamiebuilds
Copy link
Collaborator

You'll have to explain how it works, I would check the tests in the react-hot-loader repo but you don't have any... :for_shame:

@jedwards1211
Copy link

@thejameskyle it's just a development tool dude, not for production

@jamiebuilds
Copy link
Collaborator

I understand that dude, development tools need tests too.

@gaearon
Copy link
Owner Author

gaearon commented Dec 9, 2015

Actually that's exactly why this project was started. It was easier to split RHL into several different projects than to write tests for it :-) RHL just enumerated every key in module.exports and wrapped whatever looks like a React component. This is what I suggest to do here: wrap every export into a conservative runtime check. The wrapping function would be like

let wrappedComponents = [];

wrapExport(something) {
  if (
    something &&
    something.prototype &&
    something.prototype.isReactComponent && // only finds Component descendants but good enough
    wrappedComponents.indexOf(something) === -1 // don't wrap twice
  ) {
    wrappedComponent.push(something); // normal generated code would also need to do that 
    return wrapJustLikeWeWrapInGeneratedCode(something);
  }
  return something; // not an export we should hijack
}

Then every export would go through this wrapper, regardless of what's in there.
Does it make sense?

This is a runtime check but it's important for many cases where we want export a React class generated by some factory in another file, and it's essential to maintain its identity.

@solomon-gumball
Copy link

+1 Would like to see this.

I am actually working on a backbone/react application and using the react-hmre preset. This is causing react-proxy to run on our backbone views which is an issue!

@gaearon
Copy link
Owner Author

gaearon commented Jan 26, 2016

Interesting, can you show code that fails? In s separate issue.

@solomon-gumball
Copy link

@gaearon will do.

@gaearon
Copy link
Owner Author

gaearon commented Apr 18, 2016

This is fixed in React Hot Loader 3.
It is built with lessons learned from both React Hot Loader and React Transform.

I’m closing the issue as unsolvable in this repo.

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

No branches or pull requests

4 participants