Skip to content

apply isomorphic standards to userland libraries and plugins (globalThis) #1005

Description

@thescientist13

Overview

As called out in WCC and MDN, code that needs to run in multiple environments should delegate any "global" references to the new globalThis.

The globalThis property provides a standard way of accessing the global this value (and hence the global object itself) across environments. Unlike similar properties such as window and self, it's guaranteed to work in window and non-window contexts. In this way, you can access the global object in a consistent manner without having to know which environment the code is being run in. To help you remember the name, just remember that in global scope the this value is globalThis.

This means that instead of calling window.addEventListener you would want to use globalThis.addEventListener.
Each environment can choose to polyfill or support some, none, or all of these features, and the code doesn't necessarily have to worry about feature detection, e.g.

if(window) {
  // ... do stuff
}

Details

For Greenwood, this would apply to

Should also update to latest version of WCC to accommodate this.


One way to test is to pre-render the website with WCC instead of Puppeteer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIPluginsGreenwood PluginsSSRenhancementImprove something existing (e.g. no docs, new APIs, etc)

    Type

    No fields configured for Task.

    Projects

    Status
    🔖 Ready

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions