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

preventing ReferenceError #421

Merged
merged 1 commit into from
Jan 13, 2022
Merged
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
28 changes: 22 additions & 6 deletions src/Tooltip.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,31 @@
function registerEventListeners() {

if (target == null || target.length == 0) {
targetEl = null;
targetEl = null;
return;
}
else if (target instanceof HTMLElement) {
targetEl = target;

// Check if target is HTMLElement
try {
if (target instanceof HTMLElement) {
targetEl = target;
}
} catch (e) {
// fails on SSR
}
else {
targetEl = document.querySelector(`#${target}`);
}

// If targetEl has not been found yet
if (targetEl == null) {
// Check if target can be found via querySelector
try {
targetEl = document.querySelector(`#${target}`);
}
catch (e) {
// fails on SSR
}
}

// If we've found targetEl
if (targetEl) {
targetEl.addEventListener('mouseover', open);
targetEl.addEventListener('mouseleave', close);
Expand Down