solid icon indicating copy to clipboard operation
solid copied to clipboard

Using lazy-loaded components in the context fails to render.

Open thep0y opened this issue 8 months ago • 3 comments

Describe the bug

In the console, you can see the mounted message of the ButtonDemo component, but the ButtonDemo component itself failed to render. Meanwhile, there are no warnings or error messages in the console regarding the rendering failure of the component.

If you only start the development server without building, the ButtonDemo component can be rendered normally.

Your Example Website or App

https://github.com/thep0y/solid-context-demo

Steps to Reproduce the Bug or Issue

bun run build
cd example
bun run build
bun run preview

Expected behavior

The ButtonDemo component renders normally.

Screenshots or Videos

No response

Platform

  • OS: [Windows]
  • Browser: [Chrome]
  • Version: [135.0.7049.115]

Additional context

No response

thep0y avatar Apr 28 '25 03:04 thep0y

Any way to get a more minimal reproduction? This requires tracing through multiple projects to figure out where the bug is.

I made a quick playground to show Context working in a lazy component.. unless you mean in a different way? https://playground.solidjs.com/anonymous/2d6654f8-d1ee-4a7c-a079-b200b23c73d1

Maybe use something like this or a basic Stackblitz as a base.

ryansolid avatar Apr 30 '25 21:04 ryansolid

I need to try.

The current reproduction steps are based on the project I wrote, and a lot of irrelevant components have already been removed.

thep0y avatar May 01 '25 05:05 thep0y

In the reproduced component library packages, there are currently only two components. After bundling them, there might be two issues when importing the components button and toast in the example:

  • If useToast is used in ButtonDemo to get the context, it will definitely throw an error cannot find a ToastContext.
  • If useToast is not used in ButtonDemo to get the context, ButtonDemo will not be added to the DOM node, but its structure can still be printed in the console.

The most critical issue is that everything works fine in the development environment, but the above two problems only occur in the production environment.

thep0y avatar May 01 '25 05:05 thep0y