question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onServer() helper

See original GitHub issue

Feature request

Is your feature request related to a problem? Please describe.

It would be nice to have a built-in helper to detect if code is run on server or on client.

Describe the solution you’d like

function onServer() {
    return typeof window === 'undefined'
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
timneutkenscommented, Sep 21, 2019
if(typeof window === 'undefined') {
  // some code
}

Turns into this on the client-side code:

if(false) {
  // some code
}

And is tree shaken away so ends up being removed from the client-side bundle.

Increasing the api surface would make these optimizations significantly harder and non-standard.

0reactions
balazsorban44commented, Jan 31, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Magneto 2 How to call Helper function in observer file
The Magento 2 helper is the class which is used for adding functionalities to several features and can be used anywhere in the...
Read more >
seznam/visibility-observer - GitHub
The visibility observer helper smartly caches the used intersection observers, optimizing the performance of your code while providing a more convenient API.
Read more >
Is it better to use an observer or a helper? - Meteor forums
I am wondering: theoritically, if a helper runs whenever data changes, ... const userObserver = Meteor.users.find({ _id: Router.current().params.
Read more >
Helper with array observer - Questions - Ember.JS
I am trying to create a helper that is observing an array. ... addArrayObserver({ arrayWillChange() { console.log("willChange"); } ...
Read more >
Observer pattern or helper class? (php) - Stack Overflow
class Thread { // ideally make this protected and use setters / getters, // you could also consider to use an array of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found