Skip to content

Commit

Permalink
resolve buil error
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Feb 25, 2025
1 parent ab8b463 commit a5ab470
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/client/client-patch-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export const patchBrowser = (): Promise<d.CustomElementsDefineOptions> => {
}

const scriptElm = BUILD.scriptDataOpts
? win.document && Array.from(win.document.querySelectorAll('script')).find(
? win.document &&
Array.from(win.document.querySelectorAll('script')).find(
(s) =>
new RegExp(`\/${NAMESPACE}(\\.esm)?\\.js($|\\?|#)`).test(s.src) ||
s.getAttribute('data-stencil-namespace') === NAMESPACE,
Expand Down
5 changes: 1 addition & 4 deletions src/runtime/client-hydrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ export const initializeClientHydrate = (
}
}

if (
win.document &&
(!plt.$orgLocNodes$ || !plt.$orgLocNodes$.size)
) {
if (win.document && (!plt.$orgLocNodes$ || !plt.$orgLocNodes$.size)) {
// This is the first pass over of this whole document;
// does a scrape to construct a 'bare-bones' tree of what elements we have and where content has been moved from
initializeDocumentHydrate(win.document.body, (plt.$orgLocNodes$ = new Map()));
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export const addStyle = (styleContainerNode: any, cmpMeta: d.ComponentRuntimeMet
// This is only happening on native shadow-dom, do not needs CSS var shim
styleElm.innerHTML = style;
} else {
styleElm = document.querySelector(`[${HYDRATED_STYLE_ID}="${scopeId}"]`) || win.document.createElement('style');
styleElm =
document.querySelector(`[${HYDRATED_STYLE_ID}="${scopeId}"]`) || win.document.createElement('style');
styleElm.innerHTML = style;

// Apply CSP nonce to the style tag if it exists
Expand Down
9 changes: 7 additions & 2 deletions src/runtime/vdom/vdom-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ const createElm = (oldParentVNode: d.VNode, newParentVNode: d.VNode, childIndex:
} else if (BUILD.slotRelocation && newVNode.$flags$ & VNODE_FLAGS.isSlotReference) {
// create a slot reference node
elm = newVNode.$elm$ =
BUILD.isDebug || BUILD.hydrateServerSide ? slotReferenceDebugNode(newVNode) : (win.document.createTextNode('') as any);
BUILD.isDebug || BUILD.hydrateServerSide
? slotReferenceDebugNode(newVNode)
: (win.document.createTextNode('') as any);
// add css classes, attrs, props, listeners, etc.
if (BUILD.vdomAttribute) {
updateElement(null, newVNode, isSvgMode);
Expand All @@ -89,7 +91,10 @@ const createElm = (oldParentVNode: d.VNode, newParentVNode: d.VNode, childIndex:
}

if (!win.document) {
throw new Error('You are trying to render a component in a non-browser environment. This is not supported.');
throw new Error(
"You are trying to render a Stencil component in an environment that doesn't support the DOM. " +
'Make sure to populate the [`window`](https://developer.mozilla.org/en-US/docs/Web/API/Window/window) object before rendering a component.',
);
}

// create element
Expand Down
2 changes: 1 addition & 1 deletion src/testing/platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export {
supportsShadow,
} from './testing-platform';
export { flushAll, flushLoadModule, flushQueue, loadModule, nextTick, readTask, writeTask } from './testing-task-queue';
export { doc, win } from './testing-window';
export { win } from './testing-window';
export { Env } from '@app-data';
export * from '@runtime';
1 change: 0 additions & 1 deletion src/testing/platform/testing-window.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { setupGlobal } from '@stencil/core/mock-doc';

export const win = setupGlobal(global) as Window;

0 comments on commit a5ab470

Please sign in to comment.