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

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

Open
thescientist13 opened this issue Nov 20, 2022 · 0 comments
Labels
CLI enhancement Improve something existing (e.g. no docs, new APIs, etc) Plugins Greenwood Plugins SSR
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Nov 20, 2022

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.

@thescientist13 thescientist13 added enhancement Improve something existing (e.g. no docs, new APIs, etc) Plugins Greenwood Plugins CLI SSR labels Nov 20, 2022
@thescientist13 thescientist13 added this to the 1.0 milestone Nov 20, 2022
@thescientist13 thescientist13 changed the title apply isomorphic standards to userland libraries and plugins apply isomorphic standards to userland libraries and plugins (globalThis) Nov 20, 2022
@thescientist13 thescientist13 mentioned this issue Dec 10, 2022
22 tasks
@thescientist13 thescientist13 moved this from 📋 Backlog to 🔖 Ready in [Greenwood] Phase 9 - Standards and Conventions Nov 25, 2023
@thescientist13 thescientist13 moved this from 🔖 Ready to ➡ DEFERRED in [Greenwood] Phase 9 - Standards and Conventions Aug 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI enhancement Improve something existing (e.g. no docs, new APIs, etc) Plugins Greenwood Plugins SSR
Projects
Status: 🔖 Ready
Development

No branches or pull requests

1 participant