-
Notifications
You must be signed in to change notification settings - Fork 787
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(hydrate): partially revert #5838
- Loading branch information
1 parent
de88943
commit 1e2793e
Showing
6 changed files
with
220 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
test/end-to-end/src/declarative-shadow-dom/scoped-car-detail.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Component, h, Prop } from '@stencil/core'; | ||
|
||
import { CarData } from '../car-list/car-data'; | ||
|
||
@Component({ | ||
tag: 'scoped-car-detail', | ||
styleUrl: 'another-car-detail.css', | ||
scoped: true, | ||
}) | ||
export class CarDetail { | ||
@Prop() car: CarData; | ||
|
||
render() { | ||
if (!this.car) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<section> | ||
{this.car.year} {this.car.make} {this.car.model} | ||
</section> | ||
); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
test/end-to-end/src/declarative-shadow-dom/scoped-car-list.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Component, Event, EventEmitter, h, Prop } from '@stencil/core'; | ||
|
||
import { CarData } from '../car-list/car-data'; | ||
|
||
/** | ||
* Component that helps display a list of cars | ||
* @slot header - The slot for the header content. | ||
* @part car - The shadow part to target to style the car. | ||
*/ | ||
@Component({ | ||
tag: 'scoped-car-list', | ||
styleUrl: 'another-car-list.css', | ||
scoped: true, | ||
}) | ||
export class CarList { | ||
@Prop() cars: CarData[]; | ||
@Prop({ mutable: true }) selected: CarData; | ||
@Event() carSelected: EventEmitter<CarData>; | ||
|
||
componentWillLoad() { | ||
return new Promise((resolve) => setTimeout(resolve, 20)); | ||
} | ||
|
||
selectCar(car: CarData) { | ||
this.selected = car; | ||
this.carSelected.emit(car); | ||
} | ||
|
||
render() { | ||
if (!Array.isArray(this.cars)) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<ul> | ||
{this.cars.map((car) => { | ||
return ( | ||
<li class={car === this.selected ? 'selected' : ''}> | ||
<another-car-detail car={car}></another-car-detail> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { renderToString } from '../../hydrate'; | ||
import { CarData } from '../car-list/car-data'; | ||
|
||
const vento = new CarData('VW', 'Vento', 2024); | ||
const beetle = new CarData('VW', 'Beetle', 2023); | ||
|
||
describe('renderToString', () => { | ||
it('allows to hydrate whole HTML page', async () => { | ||
const { html } = await renderToString( | ||
`<html> | ||
<head> | ||
<link rel="stylesheet" href="whatever.css" > | ||
</head> | ||
<body> | ||
<div class="__next"> | ||
<main> | ||
<car-list cars=${JSON.stringify([vento, beetle])}></car-list> | ||
</main> | ||
</div> | ||
<script type="module"> | ||
import { defineCustomElements } from "./static/loader/index.js"; | ||
defineCustomElements().catch(console.error); | ||
</script> | ||
</body> | ||
</html>`, | ||
{ fullDocument: true, serializeShadowRoot: false }, | ||
); | ||
/** | ||
* starts with a DocType and HTML tag | ||
*/ | ||
expect(html.startsWith('<!doctype html><html ')).toBeTruthy(); | ||
/** | ||
* renders hydration styles and custom link tag within the head tag | ||
*/ | ||
expect(html).toContain('selected.sc-car-list{font-weight:bold;background:rgb(255, 255, 210)}</style><link rel="stylesheet" href="whatever.css"> </head> <body>') | ||
}); | ||
}); |