Skip to content

SolidJS web components is overriding jQuery #2458

@mhamri

Description

@mhamri

I'm trying to use a SolidJS web component alongside a legacy application and gradually convert it piece by piece to SolidJS.

Unfortunately, after building and including the script, jQuery stopped working.

As demonstrated in the attached image, as soon as SolidJS is added to the application, jQuery stops working.

Image

My assumption is that web components shouldn’t affect any library or global variables when they are added to the page.

my web component doesn't include any package or any code defining $. as you can see in below generated code $ is set to nulll somewhere

in case if this would help

Details (function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))r(n);new MutationObserver(n=>{for(const i of n)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function s(n){const i={};return n.integrity&&(i.integrity=n.integrity),n.referrerPolicy&&(i.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?i.credentials="include":n.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(n){if(n.ep)return;n.ep=!0;const i=s(n);fetch(n.href,i)}})();const X=!1,Y=(e,t)=>e===t,O={equals:Y};let D=G;const y=1,x=2,V={owned:null,cleanups:null,context:null,owner:null};var d=null;let $=null,ee=null,a=null,h=null,g=null,N=0;function te(e,t){const s=a,r=d,n=e.length===0,i=t===void 0?r:t,o=n?V:{owned:null,cleanups:null,context:i?i.context:null,owner:i},l=n?e:()=>e(()=>T(()=>S(o)));d=o,a=null;try{return m(l,!0)}finally{a=s,d=r}}function se(e,t){t=t?Object.assign({},O,t):O;const s={value:e,observers:null,observerSlots:null,comparator:t.equals||void 0},r=n=>(typeof n=="function"&&(n=n(s.value)),U(s,n));return[F.bind(s),r]}function v(e,t,s){const r=k(e,t,!1,y);L(r)}function ne(e,t,s){s=s?Object.assign({},O,s):O;const r=k(e,t,!0,0);return r.observers=null,r.observerSlots=null,r.comparator=s.equals||void 0,L(r),F.bind(r)}function T(e){if(a===null)return e();const t=a;a=null;try{return e()}finally{a=t}}function F(){if(this.sources&&this.state)if(this.state===y)L(this);else{const e=h;h=null,m(()=>P(this),!1),h=e}if(a){const e=this.observers?this.observers.length:0;a.sources?(a.sources.push(this),a.sourceSlots.push(e)):(a.sources=[this],a.sourceSlots=[e]),this.observers?(this.observers.push(a),this.observerSlots.push(a.sources.length-1)):(this.observers=[a],this.observerSlots=[a.sources.length-1])}return this.value}function U(e,t,s){let r=e.value;return(!e.comparator||!e.comparator(r,t))&&(e.value=t,e.observers&&e.observers.length&&m(()=>{for(let n=0;n1e6)throw h=[],new Error},!1)),t}function L(e){if(!e.fn)return;S(e);const t=N;re(e,e.value,t)}function re(e,t,s){let r;const n=d,i=a;a=d=e;try{r=e.fn(t)}catch(o){return e.pure&&(e.state=y,e.owned&&e.owned.forEach(S),e.owned=null),e.updatedAt=s+1,J(o)}finally{a=i,d=n}(!e.updatedAt||e.updatedAt<=s)&&(e.updatedAt!=null&&"observers"in e?U(e,r):e.value=r,e.updatedAt=s)}function k(e,t,s,r=y,n){const i={fn:e,state:r,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:d,context:d?d.context:null,pure:s};return d===null||d!==V&&(d.owned?d.owned.push(i):d.owned=[i]),i}function q(e){if(e.state===0)return;if(e.state===x)return P(e);if(e.suspense&&T(e.suspense.inFallback))return e.suspense.effects.push(e);const t=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt=0;s--)if(e=t[s],e.state===y)L(e);else if(e.state===x){const r=h;h=null,m(()=>P(e,t[0]),!1),h=r}}function m(e,t){if(h)return e();let s=!1;t||(h=[]),g?s=!0:g=[],N++;try{const r=e();return ie(s),r}catch(r){s||(g=null),h=null,J(r)}}function ie(e){if(h&&(G(h),h=null),e)return;const t=g;g=null,t.length&&m(()=>D(t),!1)}function G(e){for(let t=0;t=0;t--)S(e.tOwned[t]);delete e.tOwned}if(e.owned){for(t=e.owned.length-1;t>=0;t--)S(e.owned[t]);e.owned=null}if(e.cleanups){for(t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}e.state=0}function le(e){return e instanceof Error?e:new Error(typeof e=="string"?e:"Unknown error",{cause:e})}function J(e,t=d){throw le(e)}function oe(e,t){return T(()=>e(t||{}))}function ue(e,t,s){let r=s.length,n=t.length,i=r,o=0,l=0,c=t[n-1].nextSibling,u=null;for(;of-l){const A=t[o];for(;l{const l=document.createElement("template");return l.innerHTML=e,l.content.firstChild},o=()=>(n||(n=i())).cloneNode(!0);return o.cloneNode=o,o}function R(e,t,s){s==null?e.removeAttribute(t):e.setAttribute(t,s)}function K(e,t){t==null?e.removeAttribute("class"):e.className=t}function ce(e,t,s){return T(()=>e(t,s))}function B(e,t,s,r){if(s!==void 0&&!r&&(r=[]),typeof t!="function")return j(e,t,r,s);v(n=>j(e,t(),n,s),r)}function j(e,t,s,r,n){for(;typeof s=="function";)s=s();if(t===s)return s;const i=typeof t,o=r!==void 0;if(e=o&&s[0]&&s[0].parentNode||e,i==="string"||i==="number"){if(i==="number"&&(t=t.toString(),t===s))return s;if(o){let l=s[0];l&&l.nodeType===3?l.data!==t&&(l.data=t):l=document.createTextNode(t),s=_(e,s,r,l)}else s!==""&&typeof s=="string"?s=e.firstChild.data=t:s=e.textContent=t}else if(t==null||i==="boolean")s=_(e,s,r);else{if(i==="function")return v(()=>{let l=t();for(;typeof l=="function";)l=l();s=j(e,l,s,r)}),()=>s;if(Array.isArray(t)){const l=[],c=s&&Array.isArray(s);if(M(l,t,s,n))return v(()=>s=j(e,l,s,r,!0)),()=>s;if(l.length===0){if(s=_(e,s,r),o)return s}else c?s.length===0?z(e,l,r):ue(e,s,l):(s&&_(e),z(e,l));s=l}else if(t.nodeType){if(Array.isArray(s)){if(o)return s=_(e,s,r,t);_(e,s,null,t)}else s==null||s===""||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);s=t}}return s}function M(e,t,s,r){let n=!1;for(let i=0,o=t.length;i=0;o--){const l=t[o];if(n!==l){const c=l.parentNode===e;!i&&!o?c?e.replaceChild(n,l):e.insertBefore(n,s):c&&l.remove()}else i=!0}}else e.insertBefore(n,s);return[n]}function fe(e){return Object.keys(e).reduce((s,r)=>{const n=e[r];return s[r]=Object.assign({},n),Z(n.value)&&!ge(n.value)&&!Array.isArray(n.value)&&(s[r].value=Object.assign({},n.value)),Array.isArray(n.value)&&(s[r].value=n.value.slice(0)),s},{})}function ae(e){return e?Object.keys(e).reduce((s,r)=>{const n=e[r];return s[r]=Z(n)&&"value"in n?n:{value:n},s[r].attribute||(s[r].attribute=pe(r)),s[r].parse="parse"in s[r]?s[r].parse:typeof s[r].value!="string",s},{}):{}}function he(e){return Object.keys(e).reduce((s,r)=>(s[r]=e[r].value,s),{})}function de(e,t){const s=fe(t);return Object.keys(t).forEach(n=>{const i=s[n],o=e.getAttribute(i.attribute),l=e[n];o!=null&&(i.value=i.parse?W(o):o),l!=null&&(i.value=Array.isArray(l)?l.slice(0):l),i.reflect&&I(e,i.attribute,i.value,!!i.parse),Object.defineProperty(e,n,{get(){return i.value},set(c){const u=i.value;i.value=c,i.reflect&&I(this,i.attribute,i.value,!!i.parse);for(let f=0,p=this.__propertyChangedCallbacks.length;fdelete e.__updating[t])}function pe(e){return e.replace(/\.?([A-Z]+)/g,(t,s)=>"-"+s.toLowerCase()).replace("_","-").replace(/^-/,"")}function Z(e){return e!=null&&(typeof e=="object"||typeof e=="function")}function ge(e){return Object.prototype.toString.call(e)==="[object Function]"}function ye(e){return typeof e=="function"&&e.toString().indexOf("class")===0}let C;function be(){Object.defineProperty(C,"renderRoot",{value:C})}function _e(e,t){const s=Object.keys(t);return class extends e{static get observedAttributes(){return s.map(n=>t[n].attribute)}constructor(){super(),this.__initialized=!1,this.__released=!1,this.__releaseCallbacks=[],this.__propertyChangedCallbacks=[],this.__updating={},this.props={}}connectedCallback(){if(this.__initialized)return;this.__releaseCallbacks=[],this.__propertyChangedCallbacks=[],this.__updating={},this.props=de(this,t);const n=he(this.props),i=this.Component,o=C;try{C=this,this.__initialized=!0,ye(i)?new i(n,{element:this}):i(n,{element:this})}finally{C=o}}async disconnectedCallback(){if(await Promise.resolve(),this.isConnected)return;this.__propertyChangedCallbacks.length=0;let n=null;for(;n=this.__releaseCallbacks.pop();)n(this);delete this.__initialized,this.__released=!0}attributeChangedCallback(n,i,o){if(this.__initialized&&!this.__updating[n]&&(n=this.lookupProp(n),n in t)){if(o==null&&!this[n])return;this[n]=t[n].parse?W(o):o}}lookupProp(n){if(t)return s.find(i=>n===i||n===t[i].attribute)}get renderRoot(){return this.shadowRoot||this.attachShadow({mode:"open"})}addReleaseCallback(n){this.__releaseCallbacks.push(n)}addPropertyChangedCallback(n){this.__propertyChangedCallbacks.push(n)}}}function we(e,t={},s={}){const{BaseElement:r=HTMLElement,extension:n,customElements:i=window.customElements}=s;return o=>{let l=i.get(e);return l?(l.prototype.Component=o,l):(l=_e(r,ae(t)),l.prototype.Component=o,l.prototype.registeredTag=e,i.define(e,l,n),l)}}function Ce(e){const t=Object.keys(e),s={};for(let r=0;ro)}})}return s}function ve(e){if(e.assignedSlot&&e.assignedSlot._$owner)return e.assignedSlot._$owner;let t=e.parentNode;for(;t&&!t._$owner&&!(t.assignedSlot&&t.assignedSlot._$owner);)t=t.parentNode;return t&&t.assignedSlot?t.assignedSlot._$owner:e._$owner}function Se(e){return(t,s)=>{const{element:r}=s;return te(n=>{const i=Ce(t);r.addPropertyChangedCallback((l,c)=>i[l]=c),r.addReleaseCallback(()=>{r.renderRoot.textContent="",n()});const o=e(i,s);return B(r.renderRoot,o)},ve(r))}}function me(e,t,s){return arguments.length===2&&(s=t,t={}),we(e,t)(Se(s))}const Ae="_root_4gc8u_5",Ee="_card_4gc8u_27",Oe="_mizi_4gc8u_50",xe="_small_4gc8u_63",E={root:Ae,card:Ee,mizi:Oe,small:xe};var Pe=Q("

"),je=Q("");const Ne=e=>{console.log(e);let t;function s(){globalThis.SVGInject(t)}return(()=>{var r=Pe(),n=r.firstChild,i=n.firstChild,o=i.firstChild,l=i.nextSibling,c=t;return typeof c=="function"?ce(c,o):t=o,o.addEventListener("load",s),B(l,()=>e.title),B(n,(()=>{var u=ne(()=>!!e.link);return()=>u()&&(()=>{var f=je();return v(()=>R(f,"href",e.link)),f})()})(),null),v(u=>{var f=E.root,p=E.card,b=`${E.mizi} ${e.small&&E.small}`,w=e.img,A=e.title;return f!==u.e&&K(r,u.e=f),p!==u.t&&K(n,u.t=p),b!==u.a&&K(i,u.a=b),w!==u.o&&R(o,"src",u.o=w),A!==u.i&&R(o,"alt",u.i=A),u},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),r})()};me("company-card",{title:null,link:null,small:!0,img:void 0},(e,{element:t})=>(be(),oe(Ne,e)));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions