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

The context.Provider in SolidJS wraps the children in Fragments #1330

Open
1 of 12 tasks
iceprosurface opened this issue Jan 15, 2024 · 3 comments
Open
1 of 12 tasks

The context.Provider in SolidJS wraps the children in Fragments #1330

iceprosurface opened this issue Jan 15, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@iceprosurface
Copy link

I am interested in helping provide a fix!

Yes

Which generators are impacted?

  • All
  • Angular
  • HTML
  • Preact
  • Qwik
  • React
  • React-Native
  • Solid
  • Stencil
  • Svelte
  • Vue
  • Web components

Reproduction case

https://mitosis.builder.io/?outputTab=M4ewNglgJkA%3D&code=JYWwDg9gTgLgBAbzgVwM4FMDKNrrgXzgDMoIQ4ByAAQCNlgAbAE3SgDpgIB6EYHVYKgoBuAFChIsOABF0RAIbIGMAEroAdiyjFS5Cmy6yFS1Rq1sGfdCPHho8AJIBjCOoDCrmOgAe8EmUoDZ1c2F3UvXwsrGx9JeBZjZWJkdScYTnU4YPdPHxgABVIAN2AtAAowUjBUAC5EJwALRiYoDTr5dQBPABo4AHcoeTAwVmyAfjqYTpGIIhk5RWU1TVYCAEpEUTg4MNR4PfkvOABeFAxsXDKkLe24AHN0eAGhkahsso2EG9u4VphkKCZSoQapsZ7DUZhOBjMbzRKmFZQb4EG74NY3P4AzJlZEAHiYwCKAD5kdtcdkPOE8mxChASlo4EV5AxkOhjggkODXtk6gcvGDBhC3lD8PgST8fghgaDGs1Wup8KS4LiuBTcpFafTWOLbiqCcSbmsxIqgA%3D

Expected Behaviour

<IconContext.Provider value={{ wrapperIcon: state.wrapperIcon }}>
  {props.children}
</IconContext.Provider>

transform to

<IconContext.Provider
  value={{
    wrapperIcon: wrapperIcon(),
  }}
>
  <div>
    {props.children}
   </div>
</IconContext.Provider>

Actual Behaviour

<IconContext.Provider
   value={{
    wrapperIcon: wrapperIcon(),
  }}
>
  <div>
    <>{props.children}</>
  </div>
</IconContext.Provider>

Additional Information

Solid fragment are not allowed under div.

Fragments can only be used top level in JSX. Not used under a <div>.
@iceprosurface iceprosurface added the bug Something isn't working label Jan 15, 2024
@samijaber
Copy link
Contributor

This logic extracts the Provider from the original JSX and replaces it with a Fragment:

export function extractContextComponents(json: MitosisComponent) {
traverse(json).forEach(function (item) {
if (isMitosisNode(item)) {
if (item.name.endsWith('.Provider')) {
const value = item.bindings?.value?.code;
const name = item.name.split('.')[0];
const refPath = traceReferenceToModulePath(json.imports, name)!;
json.context.set[refPath] = {
name,
value: value
? parseStateObjectToMitosisState(
expressionToNode(value) as babel.types.ObjectExpression,
)
: undefined,
};
this.update(
createMitosisNode({
name: 'Fragment',
children: item.children,
}),
);
}
// TODO: maybe support Context.Consumer:
// if (item.name.endsWith('.Consumer')) { ... }
}
});
}

The fix involves inlining the Provider's children into the array of the parent, instead of adding a new node.

@JerryWu1234
Copy link
Contributor

I will pick this up

@JerryWu1234
Copy link
Contributor

image

I done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants