-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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/custom element #7971
Feat/custom element #7971
Changes from all commits
1b4c306
6cdb77e
c341485
9329e16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,7 +141,7 @@ export function defineCustomElement( | |
class VueCustomElement extends VueElement { | ||
static def = Comp | ||
constructor(initialProps?: Record<string, any>) { | ||
super(Comp, initialProps, hydrate) | ||
super(Comp, initialProps, hydrate, options.shadowRoot) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use this reference configuration method, use a config as a parameter to pass in the control #4404 , and if possible, I would like to add this pr change idea to unplugin-vue-ce There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you very much for your interest in this PR. I will seriously consider your suggestion, and I will think further about this PR. Thank! |
||
} | ||
} | ||
|
||
|
@@ -169,23 +169,33 @@ export class VueElement extends BaseClass { | |
private _resolved = false | ||
private _numberProps: Record<string, true> | null = null | ||
private _styles?: HTMLStyleElement[] | ||
private _root: ShadowRoot | HTMLElement | ||
|
||
constructor( | ||
private _def: InnerComponentDef, | ||
private _props: Record<string, any> = {}, | ||
hydrate?: RootHydrateFunction | ||
hydrate?: RootHydrateFunction, | ||
shadowRoot?: boolean | ||
) { | ||
super() | ||
|
||
if (this.shadowRoot && hydrate) { | ||
hydrate(this._createVNode(), this.shadowRoot) | ||
this._root = this.shadowRoot! | ||
hydrate(this._createVNode(), this._root) | ||
} else { | ||
if (__DEV__ && this.shadowRoot) { | ||
warn( | ||
`Custom element has pre-rendered declarative shadow root but is not ` + | ||
`defined as hydratable. Use \`defineSSRCustomElement\`.` | ||
) | ||
} | ||
this.attachShadow({ mode: 'open' }) | ||
if (shadowRoot === false) { | ||
this._root = this | ||
} else { | ||
this.attachShadow({ mode: 'open' }) | ||
this._root = this.shadowRoot! | ||
} | ||
|
||
if (!(this._def as ComponentOptions).__asyncLoader) { | ||
// for sync component defs we can immediately resolve props | ||
this._resolveProps(this._def) | ||
|
@@ -208,7 +218,7 @@ export class VueElement extends BaseClass { | |
this._connected = false | ||
nextTick(() => { | ||
if (!this._connected) { | ||
render(null, this.shadowRoot!) | ||
render(null, this._root) | ||
this._instance = null | ||
} | ||
}) | ||
|
@@ -341,7 +351,7 @@ export class VueElement extends BaseClass { | |
} | ||
|
||
private _update() { | ||
render(this._createVNode(), this.shadowRoot!) | ||
render(this._createVNode(), this._root) | ||
} | ||
|
||
private _createVNode(): VNode<any, any> { | ||
|
@@ -355,7 +365,7 @@ export class VueElement extends BaseClass { | |
instance.ceReload = newStyles => { | ||
// always reset styles | ||
if (this._styles) { | ||
this._styles.forEach(s => this.shadowRoot!.removeChild(s)) | ||
this._styles.forEach(s => this._root.removeChild(s)) | ||
this._styles.length = 0 | ||
} | ||
this._applyStyles(newStyles) | ||
|
@@ -404,7 +414,7 @@ export class VueElement extends BaseClass { | |
styles.forEach(css => { | ||
const s = document.createElement('style') | ||
s.textContent = css | ||
this.shadowRoot!.appendChild(s) | ||
this._root.appendChild(s) | ||
// record for HMR | ||
if (__DEV__) { | ||
;(this._styles || (this._styles = [])).push(s) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This modification should have nothing to do with pr, I think this modification should be avoided