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

Support SSR out of box #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wessberg/connection-observer",
"version": "1.0.5",
"version": "1.1.0",
"description": "An API that provides a way to asynchronously observe the connectedness of a target Node or querySelector inside a document",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/original/attach-shadow.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const ORIGINAL_ATTACH_SHADOW = Element.prototype.attachShadow;
export const ORIGINAL_ATTACH_SHADOW = typeof Element !== 'undefined' ? Element.prototype.attachShadow : undefined;
2 changes: 1 addition & 1 deletion src/patch/attach-shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {isShady} from "../util/is-shady";
*/
export function patchElementPrototypeAttachShadow(callback: (node: ShadowRoot) => void): void {
// If Shadow DOM is not available, or if it is based on the ShadyDOM polyfill, there's nothing (or no need) to patch
if (ORIGINAL_ATTACH_SHADOW == null || isShady()) return;
if (ORIGINAL_ATTACH_SHADOW == null || isShady() || typeof Element === 'undefined') return;

Element.prototype.attachShadow = function (this: Element, shadowRootInitDict: ShadowRootInit): ShadowRoot {
const shadowRoot = ORIGINAL_ATTACH_SHADOW.call(this, shadowRootInitDict);
Expand Down
2 changes: 1 addition & 1 deletion src/root-observer-queue/root-observer-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import {createPausableQueue} from "../observer-queue/create-pausable-queue";
import {observeRoot} from "../observe-root/observe-root";

// Creates a pausable queue and pass document.documentElement as the initial queue payload
export const rootObserverQueue = createPausableQueue(observeRoot, document.documentElement);
export const rootObserverQueue = createPausableQueue(observeRoot, typeof document !== 'undefined' ? document.documentElement : undefined);