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

ReferenceError: self is not defined - prism-keep-markup #2257

Closed
ScottAgirs opened this issue Mar 21, 2020 · 6 comments · Fixed by #2258
Closed

ReferenceError: self is not defined - prism-keep-markup #2257

ScottAgirs opened this issue Mar 21, 2020 · 6 comments · Fixed by #2258

Comments

@ScottAgirs
Copy link

Information:

  • Prism version: "prismjs": "^1.19.0"
  • Plugins: .babelrc { ... ["line-numbers", "show-language", "keep-markup"]
  • Environment: [Next.js]

Does the latest version of Prism from the download page also have this issue?
Yes

Description
After adding "keep-markup" to the plugins list, the app fails:
image

Example
Reproduction available below
PS you can stop the app from crashing by disabling "keep-markup" in .babelrc
https://codesandbox.io/s/nextjs-prismjs-slate-u5rmz

@mAAdhaTTah
Copy link
Member

What browser is this in? When I pull this up in Chrome, self definitely exists. It also exists in FF. Maybe this is server-side...?

@RunDevelopment
Copy link
Member

Why do we pass self as a parameter and then check inside the function whether it will cause a reference error?

@ScottAgirs
Copy link
Author

@mAAdhaTTah I use Chrome, also tested on Safari and Brave. I did, however, try adding the following:

const isBrowser = typeof window !== 'undefined';
if (isBrowser) {
   Prisma.highlightAll();
}

yields same result. That said, it looks like the error occurs not on the call, but on the Prism instance import itself

@RunDevelopment - I'm guessing this question is not for me(?)

@RunDevelopment
Copy link
Member

No, it wasn't. Sorry for not clarifying.

@mAAdhaTTah
Copy link
Member

@RunDevelopment Yeah, we're pretty inconsistent on how we check what the global variable is, looking at our plugins.


That said, it looks like the error occurs not on the call, but on the Prism instance import itself

That makes sense, because that's when self is first referenced. That said, it looks like the error is on the server-side, rather than in the browser. Or maybe it's both? Pretty odd...

@mAAdhaTTah
Copy link
Member

Ok. So removing the passing-in of self & document seems to resolve the issue locally for me. That's the only plugin that passes in those variables, oddly enough. Will PR shortly.

That said, there are some other underlying issues uncovered by this. line-numbers does not look good, and I'm getting Uncaught Error: Cannot resolve a Slate node from DOM node: [object HTMLDivElement] errors trying to type into the Slate editor. If Slate is wrapping each line in its own DOM node, I don't think we can guarantee that Prism will behave correctly.

mAAdhaTTah added a commit that referenced this issue Mar 21, 2020
If self or document don't exist, they'll error instead of getting to the
checks.

Fixes #2257.
mAAdhaTTah added a commit that referenced this issue Mar 21, 2020
If self or document don't exist, they'll error instead of getting to the
checks.

Fixes #2257.
mAAdhaTTah added a commit that referenced this issue Mar 21, 2020
If self or document don't exist, they'll error instead of getting to the
checks.

Fixes #2257.
quentinvernot pushed a commit to TankerHQ/prismjs that referenced this issue Sep 11, 2020
If self or document don't exist, they'll error instead of getting to the
checks.

Fixes PrismJS#2257.
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

Successfully merging a pull request may close this issue.

3 participants