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.

Make useable in all js environments

See original GitHub issue

The branch sdk should check if window exists before utilizing it. See https://github.com/BranchMetrics/smart-app-banner-branch-deep-linking-web-library/blob/master/dist/build.js#L1845

This was only discovered while running branch in a worker thread, as window is not available in that environment.

screen shot 2016-06-15 at 2 31 33 pm

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
6graNikcommented, Dec 30, 2017

yep it is because of server-side rendering, you have lines like return navigator.isCookieEnable which will fail

Workaround may be using branch only on the client, use async chunk for example

3reactions
rubinsinghcommented, Jan 16, 2018

Hey Team,

Thank you for your feedback. To get our WebSDK operable in environments where the window object is not available is a significant undertaking for the team (as you’ve seen through searching for references to the ‘window’ object).

We’ve found another area that that would need to be re-tested/potentially re-written as a result of this change. That area is related to storage i.e. how we use application, local and cookie storage in the WebSDK to store and retrieve items related to our core deep linking functionality.

We do understand your frustration though so we’ve added this as a feature request in our internal WebSDK backlog.

Incase anyone in this thread finds it useful, we have an HTTP API as an alternative:

https://github.com/BranchMetrics/branch-deep-linking-public-api

@pho3nixf1re regarding using Branch with a server side rendered react app, I wanted to share a technique I used to make Branch work in this environment.

Using the example at the following location:

https://github.com/mhart/react-server-example

I made the following changes:

  1. Added script({src: ‘https://cdn.branch.io/build.min.js’}) over at: https://github.com/mhart/react-server-example/blob/master/server.js#L61
  2. Then to use it in a component, I added the following lines in componentDidMount(): branch.init(‘insert branch key’, function(err, data) { // callback to handle err or data });

at: https://github.com/mhart/react-server-example/blob/master/App.js#L18

This worked well for me. Please feel free to shoot an email to integrations@branch.io if you’re having trouble with React and Branch.

@morenoh149 thanks for calling out the .sdk_version issue - we’ve added it to our backlog.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting Environment Variables for Node to retrieve
Environment variables (in this case) are being used to pass credentials to your application. USER_ID and USER_KEY can both be accessed from process.env....
Read more >
Node.js Everywhere with Environment Variables! - Medium
env file is a great way to see all of your environment variables in one place. Just be sure not to put them...
Read more >
Setting up a Node development environment - MDN Web Docs
You now have a Node development environment up and running on your computer that can be used for creating Express web applications.
Read more >
Environment variables in Next.js and Netlify
If you'd like to use environment variables in Next.js, make a .env.local file at the root and you can use them all there!...
Read more >
Building A JavaScript App VS Building A JavaScript Library
Compiling It · Making It Usable From Various Apps · Choosing Supported Output Formats · Choosing Supported Target Environments · Be Careful With...
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