solid icon indicating copy to clipboard operation
solid copied to clipboard

private fields not handled by proxies (f.e. createMutable)

Open trusktr opened this issue 1 month ago • 2 comments

Describe the bug

import { createMutable } from "solid-js/store";

class MyClass {
  #a = 123
  get a() { return this.#a }
  set a(val) { this.#a = val }

  constructor() {
    return createMutable(this) // comment this out and the example works
  }
}

const o = new MyClass()
console.log(o.a) // runtime error

Your Example Website or App

https://playground.solidjs.com/anonymous/553aed2c-926e-41b6-8684-c63c8122c5db

Steps to Reproduce the Bug or Issue

Run the playground.

Expected behavior

no error, "123" should be logged

Screenshots or Videos

N/A

Platform

N/A

Additional context

Solid's Proxys need to be updated to handle private fields.

trusktr avatar Nov 23 '25 22:11 trusktr

Isn't this a js limitation where proxies cannot access private class properties (at least, without very hacky and inconsistent workarounds). I just use private ts properties instead and prefix them with underscores.

Iceman8911 avatar Nov 24 '25 12:11 Iceman8911

The issue is that the getter is being binded to the proxy instead of to the original object, as private properties can only be accessed by the instance that defined it, it throws. (this doesn't match)

To fix, it needs to bind to value here, instead of p https://github.com/solidjs/solid/blob/a5b51fe200fd59a158410f4008677948fec611d9/packages/solid/store/src/mutable.ts#L120 and also the getter will bypass the proxy now, so somehow it need to be wrapped with code that provides the same functionality of the get proxy trap https://github.com/solidjs/solid/blob/a5b51fe200fd59a158410f4008677948fec611d9/packages/solid/store/src/mutable.ts#L39-L60

titoBouzout avatar Nov 24 '25 15:11 titoBouzout