Skip to content

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

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

Open
Jannchie opened this issue Mar 15, 2025 · 1 comment
Open

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

Jannchie opened this issue Mar 15, 2025 · 1 comment

Comments

@Jannchie
Copy link

Jannchie commented Mar 15, 2025

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?

@Jannchie
Copy link
Author

I just found the PlotRender in official vitepress doc is working fine and applied the above workaround..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant