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

[ssr] installWindowOnGlobal shim globalThis.global does not inherit any of the existing builtins like Promise #2118

Closed
fetherston opened this issue Sep 1, 2021 · 0 comments · Fixed by #2120
Assignees
Labels

Comments

@fetherston
Copy link

Description

The DOM shim for @lit-labs/ssr does not inherit the builtin Node APIs from the environment onto the global object. Some third party libraries like koa expect them to be there.

Steps to Reproduce

  1. Write this code
import { installWindowOnGlobal } from '@lit-labs/ssr/lib/dom-shim';
installWindowOnGlobal();
if (!global.Promise) {
    throw new Error('global.Promise is missing');
}
  1. See this output...
    It'll throw because global.Promise is undefined.

Live Reproduction Link

N/A

Expected Results

global.Promise should be the native Node Promise API

Actual Results

No error should be thrown.

Browsers Affected

N/A

@aomarks aomarks self-assigned this Sep 1, 2021
@aomarks aomarks changed the title installWindowOnGlobal shim globalThis.global does not inherit any of the existing builtins like Promise [ssr] installWindowOnGlobal shim globalThis.global does not inherit any of the existing builtins like Promise Sep 1, 2021
aomarks added a commit that referenced this issue Sep 1, 2021
…window

This means that globalThis.global will retain its Node built-ins,
whereas before it would lose anything we didn't explicitly set on
window.

Fixes #2118
aomarks added a commit that referenced this issue Sep 1, 2021
This means that globalThis.global will retain its Node built-ins, and globalThis.global === globalThis will hold, whereas before it would lose anything we didn't explicitly set on window, so something like global.Promise would be undefined.

This window.global assignment seems to have been done for compatibility with node-fetch, but I tried a fetch from the demo/global/module.js module, and the fetch seemed to work fine. Not sure if there is another invocation path I missed, but it seems ok?

Fixes #2118
@aomarks aomarks added the c1 label Oct 13, 2021
PonomareVlad pushed a commit to SvaLit/lit-async-ssr that referenced this issue Mar 27, 2022
This means that globalThis.global will retain its Node built-ins, and globalThis.global === globalThis will hold, whereas before it would lose anything we didn't explicitly set on window, so something like global.Promise would be undefined.

This window.global assignment seems to have been done for compatibility with node-fetch, but I tried a fetch from the demo/global/module.js module, and the fetch seemed to work fine. Not sure if there is another invocation path I missed, but it seems ok?

Fixes lit#2118
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants