Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hydrate): support object serialization for hydrated components #6208

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ed1e2a3
feat(hydrate): support object serialization for hydrated components
christian-bromann Mar 18, 2025
90ea840
prettier
christian-bromann Mar 18, 2025
adbef04
serialize parameters into string
christian-bromann Mar 18, 2025
e85c9c0
don't serialize primitives
christian-bromann Mar 18, 2025
b502f45
implement hydration part
christian-bromann Mar 18, 2025
0f4dc33
prettier
christian-bromann Mar 18, 2025
559edd8
add more unit tests
christian-bromann Mar 18, 2025
ddf403c
prettier
christian-bromann Mar 18, 2025
90a4cdd
revert some unneeded changes
christian-bromann Mar 18, 2025
93cf58d
better identify if value is serializable
christian-bromann Mar 18, 2025
1f52a61
properly case unknown attributes
christian-bromann Mar 18, 2025
ce86124
fix tests
christian-bromann Mar 18, 2025
243eca6
reorganisation
christian-bromann Mar 19, 2025
1fb43e9
fix unit tests
christian-bromann Mar 19, 2025
e30ea71
fix analysis tests
christian-bromann Mar 19, 2025
d6dbdf6
e2e fixes
christian-bromann Mar 19, 2025
2980c71
prettier
christian-bromann Mar 19, 2025
32615f9
progress
christian-bromann Mar 19, 2025
390fe79
skip some tests
christian-bromann Mar 19, 2025
1aa936e
prettier
christian-bromann Mar 19, 2025
fe1603b
reorg
christian-bromann Mar 19, 2025
bbc4382
fix test
christian-bromann Mar 19, 2025
03ac2d5
fix tests
christian-bromann Mar 19, 2025
188dcda
only deserialize if hydrateClientSide is set
christian-bromann Mar 19, 2025
c565edc
improve comment
christian-bromann Mar 19, 2025
655f070
more test improvements
christian-bromann Mar 19, 2025
302a004
prettier
christian-bromann Mar 19, 2025
7b108e2
revert some tests that cause test errors
christian-bromann Mar 19, 2025
a91c9a5
Revert "revert some tests that cause test errors"
christian-bromann Mar 19, 2025
3cf72e9
chore: fix tests
Mar 19, 2025
2418b84
Merge branch 'cb/prop-serialization' of github.com:stenciljs/core int…
Mar 19, 2025
603c6c3
chore: lint
Mar 19, 2025
0e5a479
chore: fix e2e tests
Mar 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ const parsePropDecorator = (

const propMeta: d.ComponentCompilerStaticProperty = {
type: typeStr,
attribute: getAttributeName(propName, propOptions),
reflect: getReflect(diagnostics, propDecorator, propOptions),
mutable: !!propOptions.mutable,
complexType: getComplexType(typeChecker, prop, type, program),
required: prop.exclamationToken !== undefined && propName !== 'mode',
Expand All @@ -106,12 +108,8 @@ const parsePropDecorator = (
getter: ts.isGetAccessor(prop),
setter: !!foundSetter,
};
if (ogPropName && ogPropName !== propName) propMeta.ogPropName = ogPropName;

// prop can have an attribute if type is NOT "unknown"
if (typeStr !== 'unknown') {
propMeta.attribute = getAttributeName(propName, propOptions);
propMeta.reflect = getReflect(diagnostics, propDecorator, propOptions);
if (ogPropName && ogPropName !== propName) {
propMeta.ogPropName = ogPropName;
}

// extract default value
Expand Down
10 changes: 8 additions & 2 deletions src/hydrate/platform/proxy-host-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getValue, parsePropertyValue, setValue } from '@runtime';
import { CMP_FLAGS, MEMBER_FLAGS } from '@utils';

import type * as d from '../../declarations';
import { deserializeProperty, SERIALIZED_PREFIX } from '../runner/serialize';

export function proxyHostElement(elm: d.HostElement, cstr: d.ComponentConstructor): void {
const cmpMeta = cstr.cmpMeta;
Expand Down Expand Up @@ -45,7 +46,7 @@ export function proxyHostElement(elm: d.HostElement, cstr: d.ComponentConstructo
let attrValue = elm.getAttribute(attributeName);

/**
* allow hydrate parameters that contain a simple object, e.g.
* Allow hydrate parameters that contain a simple object, e.g.
* ```ts
* import { renderToString } from 'component-library/hydrate';
* await renderToString(`<car-detail car=${JSON.stringify({ year: 1234 })}></car-detail>`);
Expand All @@ -60,14 +61,19 @@ export function proxyHostElement(elm: d.HostElement, cstr: d.ComponentConstructo
} catch (e) {
/* ignore */
}
} else if (attrValue?.startsWith(SERIALIZED_PREFIX)) {
/**
* Allow hydrate parameters that contain a complex non-serialized values.
*/
attrValue = deserializeProperty(attrValue);
}

const { get: origGetter, set: origSetter } =
Object.getOwnPropertyDescriptor((cstr as any).prototype, memberName) || {};

let attrPropVal: any;

if (attrValue != null) {
if (typeof attrValue !== 'undefined') {
attrPropVal = parsePropertyValue(attrValue, memberFlags);
}

Expand Down
1 change: 1 addition & 0 deletions src/hydrate/runner/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { createWindowFromHtml } from './create-window';
export { hydrateDocument, renderToString, serializeDocumentToString, streamToString } from './render';
export { deserializeProperty, serializeProperty } from './serialize';
Loading
Loading