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: use happy-dom in module #1327

Merged
merged 3 commits into from
Aug 18, 2023
Merged

Conversation

layershifter
Copy link
Contributor

@layershifter layershifter commented Aug 18, 2023

Motivation

Linaria runs code for evaluation in Node environment that does not have DOM APIs, basically following code will throw:

$ node -e "document.createElement('div')"
[eval]:1
document.createElement('div')
^

ReferenceError: document is not defined
    at [eval]:1:1
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:313:38)

Currently Linaria tries to remove all calls of DOM APIs, the problem is that there a lot of cases where this removal is incomplete or removes valid code. To solve this problem differently this PR injects Happy DOM to Module that runs evaluation.

This makes DOM APIs available for usage and removes the need to perform code removal.

Test plan

New tests have been added.

Follow ups

packages/utils/src/removeDangerousCode.ts should be refactored to avoid DOM APIs removal.

@changeset-bot
Copy link

changeset-bot bot commented Aug 18, 2023

🦋 Changeset detected

Latest commit: 68cdbf3

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

This PR includes changesets to release 15 packages
Name Type
@linaria/babel-preset Patch
@linaria/testkit Patch
@linaria/cli Patch
@linaria/esbuild Patch
linaria Patch
@linaria/rollup Patch
@linaria/stylelint Patch
@linaria/vite Patch
@linaria/webpack4-loader Patch
@linaria/webpack5-loader Patch
esbuild-example Patch
rollup-example Patch
vite-example Patch
vpssr-linaria-solid-example Patch
@linaria/webpack-loader 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

@layershifter layershifter marked this pull request as ready for review August 18, 2023 12:36
@Anber Anber merged commit ea1444f into callstack:master Aug 18, 2023
5 checks passed
@layershifter layershifter deleted the feat/happy-dom branch August 18, 2023 13:25
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.

2 participants