@igojs/signal 6.0.0-beta.15 → 6.0.0-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@igojs/signal",
3
- "version": "6.0.0-beta.15",
3
+ "version": "6.0.0-beta.16",
4
4
  "description": "Signal - Reactive frontend/SSR framework for Igo.js",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -41,8 +41,9 @@ class Igo2Component {
41
41
 
42
42
  // Server-side rendering: compute derived values (getters) for Dust templates
43
43
  static ssr(props) {
44
- const instance = new this(null);
45
44
  props = props || {};
45
+ const instance = new this(null, props);
46
+ // Ensure props are set (handles components that don't forward props to super)
46
47
  instance._props = props;
47
48
  instance.props = props;
48
49
  if (props.form) {
@@ -67,7 +68,7 @@ class Igo2Component {
67
68
  return derived;
68
69
  }
69
70
 
70
- constructor(element, template) {
71
+ constructor(element, template, props) {
71
72
 
72
73
  this.template = template;
73
74
 
@@ -96,7 +97,12 @@ class Igo2Component {
96
97
  this._derivedValues = {};
97
98
 
98
99
  if (isServer) {
100
+ this._props = props || {};
101
+ this.props = this._props;
99
102
  this.state = this._state;
103
+ if (this._props.form) {
104
+ this._state.form = this._props.form;
105
+ }
100
106
  } else {
101
107
  // Browser: hydrate props from window and element
102
108
  const globalProps = window.__signal_props || {};
@@ -44,6 +44,32 @@ describe('SignalComponent', () => {
44
44
  assert.strictEqual(derived.public, 'visible');
45
45
  });
46
46
 
47
+ it('should make props available in child constructor during ssr()', () => {
48
+ class ChildComponent extends SignalComponent {
49
+ constructor(element, props) {
50
+ super(element, 'test/template', props);
51
+ // Simulates a real component accessing this.props during construction
52
+ this.state.items = this.props.items || [];
53
+ }
54
+ get itemCount() { return this.state.items.length; }
55
+ }
56
+ const derived = ChildComponent.ssr({ items: [1, 2, 3] });
57
+ assert.strictEqual(derived.itemCount, 3);
58
+ });
59
+
60
+ it('should make form available in state during child constructor via ssr()', () => {
61
+ class FormComponent extends SignalComponent {
62
+ constructor(element, props) {
63
+ super(element, 'test/form', props);
64
+ // Simulates accessing form in constructor
65
+ this.state.validated = !!this.state.form?.email;
66
+ }
67
+ get isValid() { return this.state.validated; }
68
+ }
69
+ const derived = FormComponent.ssr({ form: { email: 'a@b.com' } });
70
+ assert.strictEqual(derived.isValid, true);
71
+ });
72
+
47
73
  it('should handle getter errors gracefully in ssr()', () => {
48
74
  class TestComponent extends SignalComponent {
49
75
  get failing() { throw new Error('DOM error'); }