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

feat(labs/ssr): Prevent exposure of window object on globalThis #3431

Merged
merged 7 commits into from Dec 13, 2022
Merged

feat(labs/ssr): Prevent exposure of window object on globalThis #3431

merged 7 commits into from Dec 13, 2022

Conversation

steveworkman
Copy link
Contributor

@steveworkman steveworkman commented Nov 7, 2022

Fixes #3412

I made an extension to the existing installWindowOnGlobal method which defaults to installing window. This makes this change non-breaking and you can opt-in to the functionality.

I've tested this with the nuxt3 plugin and it's working well - component authors will need to be exceptionally careful about using window, perhaps that analysis can be added to the testing library

@changeset-bot
Copy link

changeset-bot bot commented Nov 7, 2022

🦋 Changeset detected

Latest commit: d409602

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@lit-labs/ssr Major
@lit-labs/eleventy-plugin-lit Patch
@lit-labs/testing Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@google-cla
Copy link

google-cla bot commented Nov 7, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Member

@augustjk augustjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! Were you able to get the CLA sorted out? As noted below, we'd like to simply make no window the de facto behavior with no need for the option.

Could you also do a npm run changeset to note this change? It would be a breaking change so a major bump would make sense. I'd be happy to handle that part too if you'd like.

packages/labs/ssr/src/lib/dom-shim.ts Outdated Show resolved Hide resolved
@steveworkman
Copy link
Contributor Author

Thank you for the PR! Were you able to get the CLA sorted out? As noted below, we'd like to simply make no window the de facto behavior with no need for the option.

Could you also do a npm run changeset to note this change? It would be a breaking change so a major bump would make sense. I'd be happy to handle that part too if you'd like.

Still working on the CLA. I will make the other changes as requested

@steveworkman
Copy link
Contributor Author

PR updated with the new functionality and a changeset. Interestingly, the server and the render-lit tests both required window to be exposed as NODE_MODE switched to false at some points of the test, causing a failure in reactive-element/css-tag where global would be undefined as it was looking for window

@steveworkman
Copy link
Contributor Author

I'm still working on the CLA - legal are reviewing it now as there's other people in the org affected too

@augustjk augustjk linked an issue Dec 1, 2022 that may be closed by this pull request
Copy link
Member

@augustjk augustjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steveworkman Any update on the CLA? If it's looking like more trouble, I can make a separate PR referencing this one for credit if you don't mind. Really appreciate it!

packages/labs/ssr/src/lib/dom-shim.ts Outdated Show resolved Hide resolved
packages/labs/ssr/src/test/integration/server/server.ts Outdated Show resolved Hide resolved
@steveworkman
Copy link
Contributor Author

@steveworkman Any update on the CLA? If it's looking like more trouble, I can make a separate PR referencing this one for credit if you don't mind. Really appreciate it!

CLA signed, awaiting return from Google 🤞

@steveworkman steveworkman requested review from augustjk and removed request for justinfagnani December 2, 2022 18:07
Copy link
Member

@augustjk augustjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last bit of cleanup, #3367 just got merged so bringing in the latest from main branch will remove the need for window references in the VM module tests.

That'll also fix the breaking tests in the eleventy-plugin-lit package's test.

packages/labs/ssr/src/test/integration/server/server.ts Outdated Show resolved Hide resolved
packages/labs/ssr/src/test/lib/render-lit_test.ts Outdated Show resolved Hide resolved
Co-authored-by: Alexander Marks <aomarks@google.com>
@augustjk augustjk changed the base branch from main to labs-ssr-3.0 December 6, 2022 02:12
Copy link
Member

@augustjk augustjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! We're queuing up some breaking changes to SSR for the next release in a separate branch.

Copy link
Member

@aomarks aomarks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR!

@steveworkman
Copy link
Contributor Author

@aomarks @augustjk anything I need to do re: benchmark reporter failure?

@augustjk
Copy link
Member

augustjk commented Dec 7, 2022

anything I need to do re: benchmark reporter failure?

Nope, all set! Looking at a bit of coordination for the monorepo but I'll work on pressing the merge.

@augustjk augustjk changed the base branch from labs-ssr-3.0 to main December 13, 2022 00:28
@augustjk augustjk changed the title feat(labs/ssr): added option to prevent exposure of window object on globalThis feat(labs/ssr): Prevent exposure of window object on globalThis Dec 13, 2022
@augustjk augustjk merged commit ff637f5 into lit:main Dec 13, 2022
@steveworkman steveworkman deleted the feat/no-window-shim-3412 branch December 13, 2022 09:21
@lit-robot lit-robot mentioned this pull request Dec 15, 2022
43081j pushed a commit to 43081j/lit-html that referenced this pull request Jan 4, 2023
This was referenced Jan 9, 2023
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.

[SSR] Add option to shim without window
3 participants