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

fix(runtime-dom): compatibility of createElement in older versions of Chrome (#9614) #9615

Merged
merged 3 commits into from
Jun 6, 2024

Conversation

peixin
Copy link
Contributor

@peixin peixin commented Nov 16, 2023

#9614
Detail: https://github.com/peixin/vue3-custom-component

Issue

Vue3 custom element (Web Component) does not render below Chrome 65 (Android 8 built-in webview)

Reason

When isCustomizedBuiltIn is false, Vue3 passes undefined as the second argument to document.createElement through nodeOps.createElement when the built-in tag name is not used as a custom element. This usage does not work in Chrome versions prior to 66, meaning that the constructor and connectedCallback of the custom element will not be triggered.

Interestingly, starting from version 66, the constructor will not be triggered upon creation, but when appended to the DOM, the constructor and connectedCallback will be triggered in sequence, allowing it to function properly. In the latest version, the constructor will be triggered upon creation, and when appended to the DOM, the connectedCallback will be triggered.

Temporary solution

// file: index.html
// patch the createElement to avoid options is nullish
var _createElement = window.document.createElement;
window.document.createElement = function (tagName, options) {
    if (options) {
        return _createElement.call(window.document, tagName, options);
    } else {
        return _createElement.call(window.document, tagName);
    }
}

@peixin peixin changed the title fix: compatibility of createElement in older versions of Chrome (#9614) fix(runtime-dom): compatibility of createElement in older versions of Chrome (#9614) Nov 16, 2023
@yyx990803 yyx990803 merged commit a88295d into vuejs:main Jun 6, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

3 participants