Skip to content

Conversation

@acelyavul
Copy link

Hello,

This is related to the this issue
Logs appears in debugging mode.

Note: Also there are some vulnerabilities that can be fixed with npm audit.

Could you please review?

@chrisglein
Copy link
Collaborator

chrisglein commented Mar 13, 2023

I've been hitting #12 and looking for a fix. Found your PR linked from the issue. This PR has a bunch of whitespace/reformatting changes that are distracting from the actual fix (and probably making it less likely the repo maintainer is going to look at the PR). Is this the meaningful part of your change:

index.js

import "./prism-config.js";

prism-config.js

global.self = global;
self.Prism = { disableWorkerMessageHandler: true };

Is there more?
Looks like the same solution suggested here: PrismJS/prism#1303 (comment)

@chrisglein
Copy link
Collaborator

I've applied just the above locally and confirmed it works to suppress the messages. With one edit: no need to assign global.self.

prism-config.js

global.Prism = { disableWorkerMessageHandler: true };

@acelyavul
Copy link
Author

I've been hitting #12 and looking for a fix. Found your PR linked from the issue. This PR has a bunch of whitespace/reformatting changes that are distracting from the actual fix (and probably making it less likely the repo maintainer is going to look at the PR). Is this the meaningful part of your change:

index.js

import "./prism-config.js";

prism-config.js

global.self = global;
self.Prism = { disableWorkerMessageHandler: true };

Is there more? Looks like the same solution suggested here: PrismJS/prism#1303 (comment)

Yes, you're right :/ and this was all I changed

chrisglein added a commit to chrisglein/artificial-chat that referenced this pull request Mar 13, 2023
chrisglein added a commit to chrisglein/react-native-syntax-highlighter that referenced this pull request Mar 14, 2023
On the console you'll see a lot of errors like this:
> Uncaught SyntaxError: Unexpected token o in JSON at position 1

The reason for that can be found here:
PrismJS/prism#1303
This PR applies the recommended fix for that thread and also tried with
this PR: conorhastings#32

The fix is to add a prism-config.js that sets
`disableWorkerMessageHandler: true`

Fixes conorhastings#12
chrisglein added a commit to chrisglein/react-native-syntax-highlighter that referenced this pull request Mar 14, 2023
On the console you'll see a lot of errors like this:
> Uncaught SyntaxError: Unexpected token o in JSON at position 1

The reason for that can be found here:
PrismJS/prism#1303
This PR applies the recommended fix for that thread and also tried with
this PR: conorhastings#32

The fix is to add a prism-config.js that sets
`disableWorkerMessageHandler: true`

Fixes conorhastings#12
@chrisglein
Copy link
Collaborator

Yes, you're right :/ and this was all I changed

Created a PR that applies the minimal change: #34

@KonstantinZhukovskij
Copy link

It didn't help me. I still get an error. Are you sure it works?

@acelyavul
Copy link
Author

acelyavul commented Mar 26, 2023

It didn't help me. I still get an error. Are you sure it works?

global.self = global;
global.Prism = { disableWorkerMessageHandler: true };

Hi, it worked for me JSON syntax error in debugging mode as above. And also in jest, it was throwing an error.

@KonstantinZhukovskij
Copy link

It didn't help me. I still get an error. Are you sure it works?

global.self = global;
global.Prism = { disableWorkerMessageHandler: true };

Hi, it worked for me JSON syntax error in debugging mode as above. And also in jest, it was throwing an error.

I didn't understand what you mean. The code given is throwing an debug error.

@acelyavul
Copy link
Author

It didn't help me. I still get an error. Are you sure it works?

global.self = global;
global.Prism = { disableWorkerMessageHandler: true };

Hi, it worked for me JSON syntax error in debugging mode as above. And also in jest, it was throwing an error.

I didn't understand what you mean. The code given is throwing an debug error.

Are we talking about the same error?
This was coming from prism.

bug.PNG

@KonstantinZhukovskij
Copy link

yes

@chrisglein
Copy link
Collaborator

yes

Did you apply the whole change or just add those lines to your project?
If you read up on the thread for the issue you'll see it noted that the import order is very important, which is why those lines are put into a separate file to get imports to work.

@KonstantinZhukovskij
Copy link

image

image

image

I'll add screenshots as proof)

@acelyavul
Copy link
Author

acelyavul commented Mar 31, 2023

@KonstantinZhukovskij you're altering the module itself but dist file doesn't have the changes you made. You can put the src folder inside your app and add react-syntax-highlighter as dependecy. But you are going to have import error, you need to change them.

import React from 'react';
import { Text, ScrollView, Platform } from 'react-native';
import './prism-config.js';

import SyntaxHighlighter from 'react-syntax-highlighter';
import SyntaxHighlighterPrism from 'react-syntax-highlighter/src/prism';
import { createStyleObject } from 'react-syntax-highlighter/src/create-element';
import { defaultStyle } from 'react-syntax-highlighter/src/styles/hljs';
import { prism as prismDefaultStyle } from 'react-syntax-highlighter/src/styles/prism';
```
 This should work.

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 this pull request may close these issues.

4 participants