Skip to content

Commit

Permalink
fix: use strict mode in function which use this
Browse files Browse the repository at this point in the history
Without "use strict", `this` will be set to `globalThis` which is
typically the window object. If certain properties are set on the
window object (e.g. "window.target"), this can cause problems for the
`css` and `styled` functions.

Instead, "use strict" ensures that `this` will only have a value if it
is explicitly bound, and otherwise will be `undefined`.

Closes cristianbote#545
  • Loading branch information
jluxenberg committed Sep 6, 2023
1 parent a849b2d commit b6159d8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getSheet } from './core/get-sheet';
* @param {String|Object|Function} val
*/
function css(val) {
'use strict'; // we want "this" to be undefined instead of being globalThis, which is typically the window object
let ctx = this || {};
let _val = val.call ? val(ctx.p) : val;

Expand Down
1 change: 1 addition & 0 deletions src/styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function setup(pragma, prefix, theme, forwardProps) {
* @param {function} forwardRef
*/
function styled(tag, forwardRef) {
'use strict'; // we want "this" to be undefined instead of being globalThis, which is typically the window object
let _ctx = this || {};

return function wrapper() {
Expand Down

0 comments on commit b6159d8

Please sign in to comment.