Skip to content

HyperScript engine does not work properly with For #2453

Closed

Description

@grimalschi

Describe the bug

Function "For" in HyperScript mode loses connection with signals when list changes.

Your Example Website or App

https://playground.solidjs.com/anonymous/2103f083-762b-40be-b23f-114309a0142f

Steps to Reproduce the Bug or Issue

  1. Click "add"
  2. Click "demo"

Image

Expected behavior

Here is correct behavior using TSX:
https://playground.solidjs.com/anonymous/9392c73a-cd81-4260-9f23-508104380960

Image

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Vivaldi
  • Version: 7.0.3495.29

Additional context

I have also checked html`` function, it works as expected (https://playground.solidjs.com/anonymous/5e9b68a0-5d8f-4f30-8ec3-d4c8fb24f766).

The closest solution is to wrap children in function (https://playground.solidjs.com/anonymous/32865f62-3ba6-45f3-a0a1-e8bc9adced6a),
but in this case Solid redraws all children everytime I add new element in array, which is undesired behavior.

Image

Activity

  1. changed the title [-]HyperScript engine does not properly with For[/-] [+]HyperScript engine does not work properly with For[/+] on Mar 21, 2025
  2. ryansolid commented on Mar 27, 2025

    @ryansolid
    Member

    Thanks yeah I can reproduce. I made some pretty heavy changes to HyperScript a couple years ago to handle Context + Fragments and while it worked then, over time we have been optimizing away unnecessary wrappers in Solid core and it turns out HyperScript is the only renderer that needs them. I want to re-evaluate this solution on a whole because basically the reactivity leaks upwards here in a way that is more or less prevented by our JSX compiler and html function.

    The gist of it is that we defer evaluation here and it leads to render effects being created in the parent context instead of inside the For which means when the parent insert re-runs it inadvertently releases the render effects on the other divs. Given my current understanding of how these things should work this is all wrong.

  3. titoBouzout commented on May 1, 2025

    @titoBouzout
    Contributor
  4. ryansolid commented on Apr 24, 2026

    @ryansolid
    Member

    I did a half measure and it didnt work. The tension was I wanted to preserve how Solid returns real DOM Elements while still ensure things ran in the right context order. I tried to keep both qualities but they are at odds with each other when it comes to ownership.

    This is in a really awkward place for 1.0. Either I have to make a complete breaking change(don't return DOM Elements) or revert the half measure which is also breaking(out of order execution, missing Context lookup). Although atleast the order is fixable if the user remembers to always wrap children in thunks.. but that can be very unergonomic. I'd be more leaning to undoing the change on 1.0, but I'm also tempted to leave as is.

    I've fixed this in 2.0 with the breaking design that doesn't return real DOM Elements. It's the only reasonable thing to do here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    alternative templatingRelated to non-JSX template enginesbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions