Skip to content

Allowing custom reconciler host-context in React 18 #24138

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

Open
drcmda opened this issue Mar 21, 2022 · 0 comments
Open

Allowing custom reconciler host-context in React 18 #24138

drcmda opened this issue Mar 21, 2022 · 0 comments
Labels
React 18 Bug reports, questions, and general feedback about React 18 Type: Discussion

Comments

@drcmda
Copy link

drcmda commented Mar 21, 2022

in a custom renderer we would like to do something like this:

<inject foo="bar">
  <group>
    <group>
      <obj />
    </group>
  </group>
</inject>

obj is supposed to know it is within inject, this is possible

inject is supposed to make its props (foo="bar") the host context for all of its nested contents, obj should be able to access it. this is not possible

we create a host context like this:

getRootHostContext(rootContainer) { return {} }
getChildHostContext(parentHostContext, type, rootContainer) {
 if (type === "inject") {}
 else return parentHostContext

when getChildHostContext gets called for inject, we only have access to string type, not props. i thought i can return an empty object {} and fill it later in:

finalizeInitialChildren(instance, type, props, rootContainer, hostContext) {
  if (type === "inject) hostContext.props = props

but when finalizeInitialChildren is called for inject it refers to root context, it can't refer to its own host context that was created by getChildHostContext.

i find this puzzling, we don't seem to have any relation between a host context and the element that created it.

solution

if we can access the current context it would be very useful to create a richer host context, that will also update.

finalizeInitialChildren(instance, type, props, rootContainer, hostContext, currentContext)
prepareUpdate(instance, type, oldProps, newProps, rootContainer, hostContext, currentContext)

alternatively, allowing us to receive props would at least allow for a static host context that doesn't update but at least carrier some deeper information.

getChildHostContext(parentHostContext, type, rootContainer, props)
@drcmda drcmda added React 18 Bug reports, questions, and general feedback about React 18 Type: Discussion labels Mar 21, 2022
@drcmda drcmda changed the title Allowing custom reconciler context in React 18 Allowing custom reconciler host-context in React 18 Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
React 18 Bug reports, questions, and general feedback about React 18 Type: Discussion
Projects
None yet
Development

No branches or pull requests

1 participant