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

Enabled web worker when loading data. #1006

Closed
wants to merge 1 commit into from
Closed

Conversation

nilscb
Copy link
Collaborator

@nilscb nilscb commented May 20, 2022

No description provided.

@nilscb nilscb linked an issue May 20, 2022 that may be closed by this pull request
@nilscb nilscb added bug Something isn't working AspenTech Task owned by AspenTech map-component Issues related to the map component. labels May 20, 2022
@nilscb nilscb requested a review from hkfb May 20, 2022 17:23
Comment on lines 137 to 139
// Serve the worker as a local url. See: https://deck.gl/docs/developer-guide/loading-data#loaders-and-web-workers
const blob = new Blob([WORKER_SCRIPT], { type: "text/plain" });
const url = window.URL.createObjectURL(blob);
Copy link
Collaborator

@anders-kiaer anders-kiaer May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would require script-src blob: in CSP, which is equivalent to allowing unsafe-eval, as confirmed by https://www.w3.org/TR/CSP2/#source-list-guid-matching:

Especially for the default-src and script-src directives, policy authors should be aware that allowing "data:" URLs is equivalent to unsafe-inline and allowing "blob:" or "filesystem:" URLs is equivalent to unsafe-eval.

For deployed applications that want tight security settings, we could perhaps offer the component consumer to provide a url where the web worker script is hosted, and if not provided we do as done here (create a blob: url for script usage)?

@codecov-commenter
Copy link

codecov-commenter commented May 27, 2022

Codecov Report

Merging #1006 (a7128be) into master (c50d970) will decrease coverage by 0.02%.
The diff coverage is 16.66%.

@@            Coverage Diff             @@
##           master    #1006      +/-   ##
==========================================
- Coverage   38.59%   38.57%   -0.03%     
==========================================
  Files         138      139       +1     
  Lines        6374     6380       +6     
  Branches     1576     1580       +4     
==========================================
+ Hits         2460     2461       +1     
- Misses       3882     3887       +5     
  Partials       32       32              
Impacted Files Coverage Δ
.../components/DeckGLMap/layers/terrain/map3DLayer.ts 1.48% <0.00%> (-0.06%) ⬇️
...ponents/DeckGLMap/layers/terrain/terrain-worker.ts 100.00% <100.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@nilscb nilscb requested a review from anders-kiaer May 27, 2022 09:01
@@ -0,0 +1,1261 @@
// Serve the worker as a local url.
// See: https://deck.gl/docs/developer-guide/loading-data#loaders-and-web-workers
// This is from the script terrain-worker.js but as a string. Some symbols are escaped.
Copy link
Collaborator

@anders-kiaer anders-kiaer May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://deck.gl/docs/developer-guide/loading-data#loaders-and-web-workers, there exist bundles in node_modules/@loaders.gl/<module>/dist/<name>-loader.worker.js. Should we instead of comitting the terrain worker script to our code base, instead include it in the bundle through raw-loader in webpack (or assets/source in webpack 5) - https://v4.webpack.js.org/loaders/raw-loader/?

Pros: Reduces the amount of code we "own", and perhaps makes it easier to stay in sync with any @loaders.gl bumps we do in package.json (since they then stays in sync).

Con: You have to escape necessary symbols automatically, do the escapes you had to do @nilscb follow a pattern that is easy to automate? Why was it necessary to escape some symbols from the worker bundle?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to escape some symbols in the script because I use the script as an inlined string. If you refer to the script as a stadard extern URL it needs not to be chenaged in any way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also we are not ablde/allowed to use raw-loader in webpack 5. (Håvard would know more. I will remove the script from example data.

@nilscb nilscb requested review from hkfb and anders-kiaer June 1, 2022 07:51
@@ -419,6 +419,31 @@ Axes.args = {
},
};

// Example using externally web worker script for loading map mesh.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move this story to the map3DLayer.stories.tsx

@nilscb nilscb closed this Sep 14, 2022
@nilscb nilscb deleted the WebWorker branch December 7, 2023 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AspenTech Task owned by AspenTech bug Something isn't working map-component Issues related to the map component.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UI freezes when loading large maps
4 participants