Skip to content

Fix "document is not defined" error - #835

Merged
RobbieTheWagner merged 2 commits into
shipshapecode:masterfrom
diegohaz:patch-1
Jul 13, 2021
Merged

Fix "document is not defined" error#835
RobbieTheWagner merged 2 commits into
shipshapecode:masterfrom
diegohaz:patch-1

Conversation

@diegohaz

Copy link
Copy Markdown
Contributor

Fixes#834

I see that this was updated on #333. But isUndefined(document) will throw an error if document wasn't set in the first place, while the typeof check will not.

@RobbieTheWagner

RobbieTheWagner commented Jul 7, 2021

Copy link
Copy Markdown
Member

@diegohaz Ah, good catch! I think instead of the changes you proposed, we will want to update the util https://github.com/shipshapecode/tether/blob/master/src/js/utils/type-check.js#L38

It should check if typeof value === 'undefined'. Would you mind updating your PR?

@diegohaz

Copy link
Copy Markdown
ContributorAuthor

@rwwagner90 That will not fix the error as document will still be referenced in isUndefined(document). This isUndefined function can only be used with variables that already have been declared (so it returns true when their value is really undefined or they haven't been assigned a value yet).

It's not specific to document or window. Any variable that hasn't been declared will throw this error:

image

typeof is a special operator that bypasses this error:

image

@RobbieTheWagner
RobbieTheWagner merged commit bfc4c59 into shipshapecode:masterJul 13, 2021
@RobbieTheWagner

Copy link
Copy Markdown
Member

Thanks for the explanation @diegohaz and thanks for the PR!

@diegohaz
diegohaz deleted the patch-1 branch July 13, 2021 18:13
@github-actionsgithub-actionsBot mentioned this pull request Dec 5, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReferenceError: document is not defined

2 participants

@diegohaz@RobbieTheWagner