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

Can we still use "owner-based" context? or do "context forwarding" ? #4081

Closed
slorber opened this issue Jun 10, 2015 · 11 comments
Closed

Can we still use "owner-based" context? or do "context forwarding" ? #4081

slorber opened this issue Jun 10, 2015 · 11 comments

Comments

@slorber
Copy link
Contributor

slorber commented Jun 10, 2015

I mean we still can (in 0.13) with a warning but it will probably not be possible in the future.

I use a Tooltip positionning library but it does only accept raw html strings.
I want to be able to render React content inside the tooltips after the lib has positionned them (generally in ). It works fine with renderStaticMarkup.
There is no parent/child relationship between the tooltipable content and the tooltip (it often causes troubles with z-index: we generally want the tooltips to overflow)

My code looks like:

 var WithTooltip = React.createClass({

   componentDidMount: function() {
      setupTooltipPositioningLibrary();
      React.render(this.props.tooltipContent,this.getTooltipNode())
   },
   ...
   render: function() {
      return this.props.children; 
   }
});

It works fine.

The problem is: I'd like to be able to use the normal application context inside my own tooltip content.

Somehow I have to "forward" the context of WithTooltip to the tooltip content. Is it possible?
I'd like it to be "dynamic" and not have to maintain a list of childContextTypes etc...

The log I have is:

Warning: owner-based and parent-based contexts differ (values:frvsundefined) for key (locales) while mounting CategoryName (see: http://fb.me/react-context-by-parent) warning.js:48

@gaearon
Copy link
Collaborator

gaearon commented Jun 10, 2015

Related: #3210

@sophiebits
Copy link
Collaborator

Yeah, let's track there. cc @jimfb though.

@jimfb
Copy link
Contributor

jimfb commented Jun 11, 2015

I think this is solved by using ReactWithAddons.renderSubtreeIntoContainer. It currently handles context forwarding but not event bubbling, but it sounds like that would work for @slorber's use case.

@slorber
Copy link
Contributor Author

slorber commented Jun 11, 2015

Thanks @jimfb it seems to be what I'm looking for.

I'm not looking for event bubbling to the parent, but simply to be able to setup click listeners that I can handle on the child directly.

@jimfb is this available in 0.13? It seems not to be.

So to achieve this I'm going to wait for 0.14 right? This produces a lot of warnings in 0.13 and is really bothering me. Can we disable this warning in 0.13? I can use static markup for now and wait for 0.14 but this produce a lot of warnings :(

Also does it really work? Because here:
#3741
It seems to me the assertion that the context is forwarded has been commented.

@slorber
Copy link
Contributor Author

slorber commented Jun 11, 2015

So it seems I can get rid of warnings with production mode, but in dev it's still bothering me because of the quantity.

I've tried to monkey-patch the warning but this is not easy, as patching ReactCompositeComponent after requiring it is useless since the warning method as already been used in ReactCompositeComponentWrapper of instantiateReactComponent.
It would be nice to be able to disable selectively production warnings.

@waldreiter
Copy link
Contributor

@slorber
I have not tried, but maybe something similar like this works:

console.warn = function(text) {
  if (!text.startsWith('owner-based and parent-based contexts differ')) {
    console.log(text);
  }
};

This filters the unwanted warnings out. Note that the changed console.warn calls console.log to avoid an endless recursion.

@slorber
Copy link
Contributor Author

slorber commented Jun 11, 2015

thanks @cody this is what I've finally hacked :)

// TODO remove this after 0.14, see https://github.com/facebook/react/issues/4081
var warn = console.warn;
var warningFilterKey = function(warning) {
    return warning.indexOf("Warning: owner-based and parent-based contexts differ") >= 0
};
var throttledWarn = _.throttle(function() {
    warn.call(console,"Stample throttled warning about React owner/parent based contexts, see https://github.com/facebook/react/issues/4081 for reasons");
    warn.apply(console, arguments);
},60000);
console.warn = function() {
    if ( arguments && arguments.length > 0 && typeof arguments[0] === "string" && warningFilterKey(arguments[0]) ) {
        throttledWarn.apply(throttledWarn,arguments);
    }
    else {
        warn.apply(console, arguments);
    }
};

@jimfb
Copy link
Contributor

jimfb commented Jun 11, 2015

@slorber #3741 was never merged; the PR was closed because we figured out how to do the sync internally. The switch to parent context has happened.

@slorber
Copy link
Contributor Author

slorber commented Jun 11, 2015

thanks @jimfb but what does it mean? Will it be released in 0.14?

@jimfb
Copy link
Contributor

jimfb commented Jun 12, 2015

Yes, 0.14 will be parent-based-context, and renderSubtreeIntoContainer will be made available publicly. You can start playing with it in React 0.14-alpha3, which is up on NPM.

@slorber
Copy link
Contributor Author

slorber commented Jun 12, 2015

thanks :)

As we have short release cycles I'll keep using 0.13 with the disabled warning but will try to switch to 0.14 as soon as we have a stable RC (after fixing the addons.classSet and body mouting errors :))

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

5 participants