Skip to content

Commit f7ecec3

Browse files
johnjenkinsJohn Jenkins
andauthored
fix(ssr): multiple component instances sharing initial properties (#6126)
Co-authored-by: John Jenkins <[email protected]>
1 parent 5a7ab24 commit f7ecec3

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/hydrate/platform/proxy-host-element.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ export function proxyHostElement(elm: d.HostElement, cstr: d.ComponentConstructo
108108

109109
// if we have a parsed value from an attribute / or userland prop use that first.
110110
// otherwise if we have a getter already applied, use that.
111-
return attrPropVal !== undefined
112-
? attrPropVal
111+
const ref = getHostRef(this);
112+
return ref.$instanceValues$?.get(memberName) !== undefined
113+
? ref.$instanceValues$?.get(memberName)
113114
: origGetter
114115
? origGetter.apply(this)
115116
: getValue(this, memberName);

test/end-to-end/src/ssr-runtime-decorators/ssr-runtime-decorators.e2e.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,34 @@ describe('different types of decorated properties and states render on both serv
107107
expect(await txt('basicState')).toBe('basicState');
108108
expect(await txt('decoratedState')).toBe('10');
109109
});
110+
111+
it('renders different values on different component instances ', async () => {
112+
const doc = await renderToString(`
113+
<runtime-decorators></runtime-decorators>
114+
<runtime-decorators
115+
decorated-prop="200"
116+
decorated-getter-setter-prop="-5"
117+
basic-prop="basicProp via attribute"
118+
basic-state="basicState via attribute"
119+
decorated-state="decoratedState via attribute"
120+
></runtime-decorators>
121+
`);
122+
html = doc.html;
123+
124+
// first component should have default values
125+
126+
expect(htmlTxt('basicProp')).toBe('basicProp');
127+
expect(htmlTxt('decoratedProp')).toBe('-5');
128+
expect(htmlTxt('decoratedGetterSetterProp')).toBe('999');
129+
expect(htmlTxt('basicState')).toBe('basicState');
130+
expect(htmlTxt('decoratedState')).toBe('10');
131+
132+
page = await newE2EPage({ html, url: 'https://stencil.com' });
133+
134+
expect(await txt('basicProp')).toBe('basicProp');
135+
expect(await txt('decoratedProp')).toBe('-5');
136+
expect(await txt('decoratedGetterSetterProp')).toBe('999');
137+
expect(await txt('basicState')).toBe('basicState');
138+
expect(await txt('decoratedState')).toBe('10');
139+
});
110140
});

0 commit comments

Comments
 (0)