-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compiler): allow disabling the injected hydration stylesheet (#2989
) provide a new `stencil.config.ts` option called `invisiblePrehydration` Ionic has an opinion to visually hide components while they are not hydrated by automatically injecting a stylesheet into the head of a document containing a css ruleset setting visibility: hidden on each of compiled components, only until they have a hydrated class. this option defaults to true, in order to allow for backwards compatibility with previous versions of Stencil 2.X. when set to `false`, consumers may opt-out of that Ionic opinion, so that they can use their own fallback styles, and more closely resemble the HTML Spec around Shadow DOM, Slots, and Dehydrated Web Components. STENCIL-23: Stencil.js: Allow turning off hydrated styles
- Loading branch information
1 parent
ac49d7c
commit a3d2928
Showing
28 changed files
with
254 additions
and
5 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
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
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
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
6 changes: 6 additions & 0 deletions
6
test/karma/test-app/invisible-prehydration-default/index.html
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,6 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf8"> | ||
<script src="/build/testinvisibledefaultprehydration.esm.js" type="module"></script> | ||
<script src="/build/testinvisibledefaultprehydration.js" nomodule></script> | ||
|
||
<prehydrated-styles></prehydrated-styles> |
17 changes: 17 additions & 0 deletions
17
test/karma/test-app/invisible-prehydration-default/karma.spec.ts
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,17 @@ | ||
import { setupDomTests } from '../util'; | ||
|
||
describe('invisible-prehydration-default', () => { | ||
const { setupDom, tearDownDom, tearDownStylesScripts } = setupDomTests(document); | ||
|
||
afterEach(tearDownDom); | ||
|
||
it('the style element will not be placed in the head', async () => { | ||
tearDownStylesScripts(); | ||
await setupDom('/invisible-prehydration-default/index.html', 1000); | ||
|
||
// Is the component hydrated? | ||
expect(document.querySelector('prehydrated-styles').innerHTML).toEqual('<div>prehydrated-styles</div>'); | ||
|
||
expect(document.head.querySelectorAll('style[data-styles]').length).toEqual(1); | ||
}); | ||
}); |
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,6 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf8"> | ||
<script src="/build/testinvisiblefalseprehydration.esm.js" type="module"></script> | ||
<script src="/build/testinvisiblefalseprehydration.js" nomodule></script> | ||
|
||
<prehydrated-styles></prehydrated-styles> |
17 changes: 17 additions & 0 deletions
17
test/karma/test-app/invisible-prehydration-false/karma.spec.ts
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,17 @@ | ||
import { setupDomTests } from '../util'; | ||
|
||
describe('invisible-prehydration-false', () => { | ||
const { setupDom, tearDownDom, tearDownStylesScripts } = setupDomTests(document); | ||
|
||
afterEach(tearDownDom); | ||
|
||
it('the style element will not be placed in the head', async () => { | ||
tearDownStylesScripts(); | ||
await setupDom('/invisible-prehydration-false/index.html', 1000); | ||
|
||
// Is the component hydrated? | ||
expect(document.querySelector('prehydrated-styles').innerHTML).toEqual('<div>prehydrated-styles</div>'); | ||
|
||
expect(document.head.querySelectorAll('style[data-styles]').length).toEqual(0); | ||
}); | ||
}); |
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,6 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf8"> | ||
<script src="/build/testinvisibletrueprehydration.esm.js" type="module"></script> | ||
<script src="/build/testinvisibletrueprehydration.js" nomodule></script> | ||
|
||
<prehydrated-styles></prehydrated-styles> |
17 changes: 17 additions & 0 deletions
17
test/karma/test-app/invisible-prehydration-true/karma.spec.ts
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,17 @@ | ||
import { setupDomTests } from '../util'; | ||
|
||
describe('invisible-prehydration-true', () => { | ||
const { setupDom, tearDownDom, tearDownStylesScripts } = setupDomTests(document); | ||
|
||
afterEach(tearDownDom); | ||
|
||
it('the style element will not be placed in the head', async () => { | ||
tearDownStylesScripts(); | ||
await setupDom('/invisible-prehydration-true/index.html', 1000); | ||
|
||
// Is the component hydrated? | ||
expect(document.querySelector('prehydrated-styles').innerHTML).toEqual('<div>prehydrated-styles</div>'); | ||
|
||
expect(document.head.querySelectorAll('style[data-styles]').length).toEqual(1); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/www |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 @@ | ||
{ | ||
"name": "test-invisible-prehydration", | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.js", | ||
"collection": "dist/collection/collection-manifest.json", | ||
"types": "dist/types/components.d.ts" | ||
} |
37 changes: 37 additions & 0 deletions
37
test/karma/test-invisible-prehydration/src/components.d.ts
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,37 @@ | ||
/* eslint-disable */ | ||
/* tslint:disable */ | ||
/** | ||
* This is an autogenerated file created by the Stencil compiler. | ||
* It contains typing information for all components that exist in this project. | ||
*/ | ||
import { HTMLStencilElement, JSXBase } from "@stencil/core/internal"; | ||
export namespace Components { | ||
interface PrehydratedStyles { | ||
} | ||
} | ||
declare global { | ||
interface HTMLPrehydratedStylesElement extends Components.PrehydratedStyles, HTMLStencilElement { | ||
} | ||
var HTMLPrehydratedStylesElement: { | ||
prototype: HTMLPrehydratedStylesElement; | ||
new (): HTMLPrehydratedStylesElement; | ||
}; | ||
interface HTMLElementTagNameMap { | ||
"prehydrated-styles": HTMLPrehydratedStylesElement; | ||
} | ||
} | ||
declare namespace LocalJSX { | ||
interface PrehydratedStyles { | ||
} | ||
interface IntrinsicElements { | ||
"prehydrated-styles": PrehydratedStyles; | ||
} | ||
} | ||
export { LocalJSX as JSX }; | ||
declare module "@stencil/core" { | ||
export namespace JSX { | ||
interface IntrinsicElements { | ||
"prehydrated-styles": LocalJSX.PrehydratedStyles & JSXBase.HTMLAttributes<HTMLPrehydratedStylesElement>; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
test/karma/test-invisible-prehydration/src/prehydrated-styles/prehydrated-styles.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,10 @@ | ||
import { Component, h } from '@stencil/core'; | ||
|
||
@Component({ | ||
tag: 'prehydrated-styles', | ||
}) | ||
export class PrehydratedStyles { | ||
render() { | ||
return <div>prehydrated-styles</div>; | ||
} | ||
} |
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,15 @@ | ||
import { Config } from '../../../dist/declarations'; | ||
|
||
export const config: Config = { | ||
namespace: 'TestInvisibleDefaultPrehydration', | ||
tsconfig: 'tsconfig.json', | ||
outputTargets: [ | ||
{ | ||
type: 'www', | ||
dir: '../www', | ||
empty: false, | ||
indexHtml: 'prehydrated-styles.html', | ||
serviceWorker: null, | ||
}, | ||
], | ||
}; |
16 changes: 16 additions & 0 deletions
16
test/karma/test-invisible-prehydration/stencil.invisiblePrehydrationFalse.config.ts
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,16 @@ | ||
import { Config } from '../../../dist/declarations'; | ||
|
||
export const config: Config = { | ||
namespace: 'TestInvisibleFalsePrehydration', | ||
tsconfig: 'tsconfig.json', | ||
invisiblePrehydration: false, | ||
outputTargets: [ | ||
{ | ||
type: 'www', | ||
dir: '../www', | ||
empty: false, | ||
indexHtml: 'prehydrated-styles.html', | ||
serviceWorker: null, | ||
}, | ||
], | ||
}; |
16 changes: 16 additions & 0 deletions
16
test/karma/test-invisible-prehydration/stencil.invisiblePrehydrationTrue.config.ts
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,16 @@ | ||
import { Config } from '../../../dist/declarations'; | ||
|
||
export const config: Config = { | ||
namespace: 'TestInvisibleTruePrehydration', | ||
tsconfig: 'tsconfig.json', | ||
invisiblePrehydration: true, | ||
outputTargets: [ | ||
{ | ||
type: 'www', | ||
dir: '../www', | ||
empty: false, | ||
indexHtml: 'prehydrated-styles.html', | ||
serviceWorker: null, | ||
}, | ||
], | ||
}; |
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,32 @@ | ||
{ | ||
"compilerOptions": { | ||
"alwaysStrict": true, | ||
"allowSyntheticDefaultImports": true, | ||
"allowUnreachableCode": true, | ||
"declaration": false, | ||
"resolveJsonModule": true, | ||
"experimentalDecorators": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"jsx": "react", | ||
"jsxFactory": "h", | ||
"lib": [ | ||
"dom", | ||
"es2017" | ||
], | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"noImplicitAny": false, | ||
"noImplicitReturns": false, | ||
"noUnusedLocals": false, | ||
"noUnusedParameters": false, | ||
"pretty": true, | ||
"target": "es2017", | ||
"baseUrl": ".", | ||
"paths": { | ||
"@stencil/core": ["../../../internal"], | ||
"@stencil/core/internal": ["../../../internal"], | ||
"@stencil/core/testing": ["../../../testing"] | ||
} | ||
}, | ||
"include": ["src"] | ||
} |
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