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

unqualified reference to window breaks usage in workers #5252

Closed
AprilArcus opened this issue Jul 10, 2023 · 1 comment
Closed

unqualified reference to window breaks usage in workers #5252

AprilArcus opened this issue Jul 10, 2023 · 1 comment

Comments

@AprilArcus
Copy link

Describe the bug

I am building a Worker for my team's custom language, and I want to obtain ace modules from ace-builds inside a Worker like so:

import * as ace from 'ace-builds';
const { Mirror } = ace.require('ace/worker/mirror');

I understand that much of Ace only works on the UI thread, but some components are useful inside workers and it is preferable to rely on ace-builds a single source of truth rather than acquiring CommonJS sources from ace-code. In addition to de-duplicating shared code, this would prevent the version of ace-builds and ace-code from going out of sync as other developers take over this project.

However, the unqualified references to window as a free variable in the exportAce function in Makefile.dryice.js ll. 792-798 crashes the worker at module init time.

Notably, ace/build_support/mini_require.js ll. 41-42 and ace/lib/ace/loader_build.js ll. 14-16 do not suffer from this same problem, obtaining a reference to global in a worker-safe manner.

Expected Behavior

import * as ace from 'ace-builds' and calling ace.require() should function correctly inside a Worker.

Current Behavior

import * as ace from 'ace-builds' and calling ace.require() crashes with a ReferenceError at module load time when window is referenced as a free variable.

Reproduction Steps

please @ me if you really need this :)

Possible Solution

Replace references to window in Makefile.dryice.js with

(function () { return this || typeof window != "undefined" && window; })

to match build_support/mini_require.js and lib/ace/loader_build.js, or replace all three with globalThis.

Additional Information/Context

No response

Ace Version / Browser / OS / Keyboard layout

1.8.1 / Chrome / Linux / QWERTY

@akoreman
Copy link
Contributor

akoreman commented Aug 7, 2023

Will be included in the next ace release (1.24.0)

@akoreman akoreman closed this as completed Aug 7, 2023
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

3 participants