Skip to content

deno server-side-render error #573

@ro-bsBear

Description

@ro-bsBear

Error

Any attempt to render goober styles within a deno instance results in ReferenceError: document is not defined

Environment

I'm the first to admit the problem might be a configuration problem on my end.

OS:  Ubuntu 20.04.6 LTS
deno:  1.38.4 (release, x86_64-unknown-linux-gnu)
v8:  12.0.267.1
typescript:  5.2.2
goober:  2.1.13

Steps to reproduce

  • install deno
  • copy any goober example source to file
  • deno run example.js

Investigation

Apparently, there is an empty? window object in the global namespace within the deno environment. I don't know why, other than deno is aiming towards creating a browser environment on the server (somewhat) for cross-compatible code. However, there is no default document-object/DOM.

Hence, in src/core/get-sheet.js

export let getSheet = (target) => {
    if (typeof window === 'object') {   // THIS TRIGGERS AS TRUE
        return (...
            Object.assign((target || document.head)... )   // THIS CAUSES REFERENCE ERROR
        ).firstChild;
    }

Note: It still works fine in node.js because node does not have a window object—and obviously the browser which has both.

Suggested Fix

export let getSheet = (target) => {
    if (typeof window === 'object' && typeof document === 'object') {

I just don't know if that would break something somewhere, like if target has a passed value.

Urgency

Low: For my own uses I cloned the repo and hacked a local copy, then bundled the official version for client-side. Doesn't help anyone else, but...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions