Skip to content

[SSR] Cannot read properties of undefined (reading 'Event') #2299

@Jannchie

Description

@Jannchie

During SSR rendering, an error occurs: Cannot read properties of undefined (reading 'Event'). The specific location of the error is in: plot.js:183:59. https://github.com/observablehq/plot/blame/90a56897cabda400e2b7537f8ecbbd2cebd18f7f/src/plot.js#L183

The reason might be that in the SSR environment, a virtual implementation of the Document element is needed. However, the example provided (which I referenced from this Observable example) is somewhat outdated.

I added the following line of code in the constructor of Document, to work around this issue:

class Document {
  constructor() {
    this.documentElement = new Element(this, 'html');
    this.defaultView = { Event }; // workaround
  }
  // other things
}

Perhaps the example file needs to be updated?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions