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

Manual annotations removed by worker #483

Open
anderoonies opened this issue Jul 2, 2018 · 5 comments
Open

Manual annotations removed by worker #483

anderoonies opened this issue Jul 2, 2018 · 5 comments

Comments

@anderoonies
Copy link

anderoonies commented Jul 2, 2018

Problem

I'm rendering a react-ace component with annotations like this:

<ReactAce
  mode={'javascript'}
  // ...
  annotations={[{row: 0, column: 0, type: 'error', text: 'Some error.'}]}
/>

The manual annotation will show up briefly, then be removed once the worker runs.
This gif shows a page refresh. On each page load the annotation shows up, but is then removed.
annotation

I've disabled the worker with setOptions={{useWorker: false}}, but this also disables annotations done manually.

Thanks!

@charlesgiroux
Copy link

I feel like there should be 2 sets of annotations. The manually added annotations and the ones generated by the mode's parser. I think they currently collide and erase one another...

@anderoonies
Copy link
Author

yeah, that's what's happening. i'm not sure if it's possible to have annotations exist outside of the lifecycle of the worker or not.

@mfalade
Copy link

mfalade commented Feb 27, 2019

I'm facing the same challenge.
I want to be able to add custom annotations to the editor, while still preserving the annotations by the worker.

After I set my custom annotations, the worker's annotations override mine.
I have seen suggestions to disable the worker like so.

setOptions={{useWorker: false}}

Doing this diables the worker's annotation however so all my linting/syntax highlighting is gone. (not quite what I want)

I want to be able to merge the worker's annotation with my custom annotation.

Can someone suggest how to go about this ?

@Ranjeet-Naidu
Copy link
Contributor

Hi , I'm in a similar situation, unable to add custom error messages. Any solution?

@bkemper
Copy link

bkemper commented May 20, 2019

Instead of using the annotations prop, I manually setAnnotations.

const Editor = ({ annotations: customAnnotations = [], value }) => {
  const [annotations, setAnnotations] = useState([]);
  const [editor, setEditor] = useState();

  const nextAnnotations = [
    ...annotations.filter(({ custom }) => !custom),  // annotations by worker
    ...customAnnotations.map((annotation) => ({ ...annotation, custom: true })) // flag for exclusion
  ];

  useEffect(() => {
    if (editor) {
      editor.getSession().setAnnotations(nextAnnotations);
    }
  }, [editor, JSON.stringify(nextAnnotations)]);

  return (
    <ReactAce
      mode="html"
      onLoad={setEditor}
      onValidate={setAnnotations}
      setOptions={{ useWorker: true }}
      value={value}
   />
}

danigm added a commit to endlessm/hack-web that referenced this issue May 11, 2020
There's a bug in the AceEditor when combining custom annotations with
worker:
securingsincity/react-ace#483

This patch tries to mitigate this problem with a custom method linked to
the onValidate signal that checks if the custom annotaions are part of
the editor annotations and adding them if they are not present.

https://phabricator.endlessm.com/T30063
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants