Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Editor worker is loaded twice #10

Closed
blutorange opened this issue Aug 26, 2019 · 6 comments
Closed

Editor worker is loaded twice #10

blutorange opened this issue Aug 26, 2019 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@blutorange
Copy link
Owner

When the language mode is one without a special worker (eg. SCSS), the editor.worker.js is loaded twice.

This is because monaco editor calls the worker factory (a) for the language-specific worker and (b) for the general editor worker. The getScriptName function is implemented as:

function getScriptName(label) {
  if (label === "json") {
    return "json.worker.js";
  }
  if (label === "css") {
    return "css.worker.js";
  }
  if (label === "html") {
    return "html.worker.js";
  }
  if (label === "typescript" || label === "javascript") {
    return "ts.worker.js";
  }
  return "editor.worker.js";
}

Also, when loading multiple instances of the monaco editor, it needs to checked as well whether that may result in workers being loaded multiple times

@blutorange blutorange added the bug Something isn't working label Aug 26, 2019
@blutorange blutorange self-assigned this Aug 26, 2019
@blutorange
Copy link
Owner Author

Monaco editor wants the css worker for "scss" and "less" files as well

blutorange added a commit that referenced this issue Aug 30, 2019
@blutorange
Copy link
Owner Author

No error seems to appear anymore. Still, when there are eg. two JavaScript editors on the same page, the ts.worker is sometimes loaded twice and sometimes only once.

@ianberdin
Copy link

I have the same issue.

Manaco editor load multiple times, if another one not yet downloaded (it's possibly only via network, not locally).
As result: downloading two and more workers.

@blutorange
Copy link
Owner Author

blutorange commented Sep 5, 2019

Did you try with latest version 0.17.2 (where I added some logic for editors to wait until the libraries are downloaded)? Could you post the xhtml you're using?

@ianberdin
Copy link

NPM has not 0.17.2 version

@blutorange
Copy link
Owner Author

This is a maven project, you don't download it from npm:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    
    ...
    
    <dependencies>
        <dependency>
            <groupId>com.github.blutorange</groupId>
            <artifactId>primefaces.monaco</artifactId>
            <version>0.17.2</version>
        </dependency>
    </dependencies>
</project>

Major and semver number is the same as the monaco editor version. Patch version is for this project.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants