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

Add regenerator-runtime as a polyfill for async/await #20761

Merged
merged 1 commit into from
Jan 16, 2021

Conversation

marcofugaro
Copy link
Contributor

Related issue: #20754 (comment)

Description
regenerator-runtime is also needed to polyfill async/await for IE11. It's a dependency which babel doesn't include by default. More details about this procedure in this guide.

I added the library as a poyfill and used the @rollup/plugin-node-resolve plugin to import it directly from node_modules.

✅ I tested the new build with the PR #20754 and it fixes the issue with misc_legacy.

@DefinitelyMaybe
Copy link
Contributor

nice! async/await here we come

@mrdoob mrdoob added this to the r125 milestone Jan 16, 2021
@mrdoob mrdoob merged commit 8091046 into mrdoob:dev Jan 16, 2021
@mrdoob
Copy link
Owner

mrdoob commented Jan 16, 2021

Thanks!

@arikwex
Copy link
Contributor

arikwex commented Feb 26, 2021

Hello all,
I think that this change has introduce a CSP issue to the tune of:

Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script

Looking at the build since r125, we can see the following:

try {
    regeneratorRuntime = runtime;
} catch (accidentalStrictMode) {
    // This module should not be running in strict mode, so the above
    // assignment should always work unless something is misconfigured. Just
    // in case runtime.js accidentally runs in strict mode, we can escape
    // strict mode using a global Function call. This could conceivably fail
    // if a Content Security Policy forbids using Function, but in that case
    // the proper solution is to fix the accidental strict mode problem. If
    // you've misconfigured your bundler to force strict mode and applied a
    // CSP to forbid Function, and you're not willing to fix either of those
    // problems, please detail your unique predicament in a GitHub issue.
    Function("r", "regeneratorRuntime = r")(runtime);
}

The problematic line seems to live here (commented it out to verify): e677e95#diff-ae80df62f9f5c7165b96cece03e3ad2dc1e16b90770c9d59683eabc1b529d9eeR280
From the comment in the build about fixing the CSP, it seems like there's no out-of-threejs solution since the 'use strict' is baked in to the build (unless I'm missing something).

fwiw the three.module.js build doesn't have this issue.

Does anyone have recommendations of how to move forward with a fix here? Migrating to use the three.module.js is viable (but high effort), and ultimately doesn't solve the core issue with the other build.

@arikwex
Copy link
Contributor

arikwex commented Feb 26, 2021

If I use strict: false for the three.js and three.min.js builds, that does solve my issue. I'm not familiar enough with the implications of making such a change... but these things seems to be competing (use strict vs. regenerator-runtime + CSP).

@marcofugaro
Copy link
Contributor Author

@arikwex it's an issue with babel and your current setup, what tools are you using?

Adding var regeneratorRuntime; also before the three.js bundle should fix it.

@arikwex
Copy link
Contributor

arikwex commented Feb 26, 2021

Thanks for that @marcofugaro. We're using brunch js. Your suggestion to add var regeneratorRuntime; does fix this.

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.

5 participants