Skip to content

Global variable clashes for Vue dev tools hooks #14335

@d1820

Description

@d1820

Vue version

3.5.26

Link to minimal reproduction

Can not provide

Steps to reproduce

compile vue 3 application into single js file, side load it into an existing site where buffer already exists on the window object. error is thrown.

Problem source

let buffer = []; //OFFENDING VAR
function setDevtoolsHook$1(hook, target) {
    var _a2, _b2;
    devtools$1 = hook;
    if (devtools$1) {
        devtools$1.enabled = true;
        buffer.forEach( ({event: event2, args}) => devtools$1.emit(event2, ...args));
        buffer = [];
    } else if (// handle late devtools injection - only do this if we are in an actual
    // browser environment to avoid the timer handle stalling test runner exit
    // (#4815)
    typeof window !== "undefined" && // some envs mock window but not fully
    window.HTMLElement && // also exclude jsdom
    // eslint-disable-next-line no-restricted-syntax
    !((_b2 = (_a2 = window.navigator) == null ? void 0 : _a2.userAgent) == null ? void 0 : _b2.includes("jsdom"))) {
        const replay = target.__VUE_DEVTOOLS_HOOK_REPLAY__ = target.__VUE_DEVTOOLS_HOOK_REPLAY__ || [];
        replay.push( (newHook) => {
            setDevtoolsHook$1(newHook, target);
        }
        );
        setTimeout( () => {
            if (!devtools$1) {
                target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
                buffer = [];
            }
        }
        , 3e3);
    } else {
        buffer = [];
    }
}

What is expected?

vue variables placed on global scope should have a vue_ prefix or something to ensure there are no clashes with other frameworks, libs, or source using the same names

What is actually happening?

console error breaking application
Uncaught SyntaxError: Identifier 'buffer' has already been declared

System Info

Chrome latest

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    need more infoFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions