Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Add Browsersync for mobile development testing #712

Merged
merged 3 commits into from
Sep 4, 2018
Merged

Conversation

t-kelly
Copy link
Contributor

@t-kelly t-kelly commented Aug 24, 2018

image 1

What are you trying to accomplish with this PR?

Fixes #594

Adds Browsersync so that your development store with assets being served from your local asset server is accessible to other devices on your local network.

TODO

@dan-gamble
Copy link
Contributor

I've given this a run locally and it seems to work well on my desktop like it usually was.

I can access the site via the browser sync url on my phone and that works but i don't get the assets. The error i'm getting is a https://localhost:3001/theme.index.js can't be found. Should this be using the browser sync ip as opposed to localhost?

https://i.imgur.com/0m1wnSu.png

@dan-gamble
Copy link
Contributor

Just to add to this if i update my local domain to be my internal IP i.e. domain: 'https://192.168.0.28', then it works 👍

@dan-gamble
Copy link
Contributor

To add to this. In IE11 everything seems to be working okay but the scripts aren't being loaded. The line is there but they don't seem to appear in the network tab so not quite sure what's going on. Could be a defer issue that isn't necessarily related to this.

@el-rotny
Copy link

el-rotny commented Aug 29, 2018 via email

@t-kelly
Copy link
Contributor Author

t-kelly commented Aug 29, 2018

Should this be using the browser sync ip as opposed to localhost?

Nope. localhost:3001 should work fine.

In IE11 everything seems to be working okay but the scripts aren't being loaded.

I'll take a look.

Just to add to this if i update my local domain to be my internal IP then it works:

Shouldn't need to do this.

@dan-gamble are you accessing your dev store externally via the myshopify.com URL or via your IP:Port (in your case https://192.168.0.28:3000). You should be using the IP:port as it will make sure localhost:3001 is pointing to the localhost on your dev machine.

@t-kelly
Copy link
Contributor Author

t-kelly commented Aug 29, 2018

If I add:

  socket: {
    domain: 'https://localhost:3000',
  },

to the browswersync config, the UI loads on 192.168.x.x:3002 but not localhost:3002. Going open a new issue in Browsersync repo.

@dan-gamble
Copy link
Contributor

Hey @t-kelly. I was accessing the site via 192.168.0.28:3000 in my virtual machine and on my iPhone in both cases and it was blanking out. Let me give it another quick try to see if i was doing something silly.

@dan-gamble
Copy link
Contributor

Hi Thomas,

I should've clarified my findings a bit more. The https://192.168.0.28:3000 works totally fine on yarn start without the domain bit. But that points to the "live" theme. If i add ?preview_theme_id=xxxxx so it's https://192.168.0.28:3000?preview_theme_id=xxxxx then the assets no long work unless i have the domain present in slate.config.js.

IE11 also works totally fine until the ?preview_theme_id=xxxxx is added where then even with the domain it doesn't seem to load assets.

@t-kelly
Copy link
Contributor Author

t-kelly commented Aug 29, 2018

@dan-gamble I was hoping preview_theme_id was being passed in the proxyReq setting I setup. Will validate what's up there.

@t-kelly
Copy link
Contributor Author

t-kelly commented Aug 31, 2018

Okay -- I've done some more work. Slate will now default to using your local IP address to reference assets instead of localhost. This will enable developers to access their dev site on their phone without having to deal with the complexities of SSL + localhost. Note, you will still need to visit the Asset Server URL at least once to tell your browser to trust it.

I now do a check when firing up the dev environment to see if your local IP is public or private. If it is private we can use it securely for external testing. If it is public, the CLI recommends you continue with external testing disabled because it's not a good idea to post your public IP on a live Shopify store.

Final test to see if it works? I'll do a code cleanup after because I've made a mess of things now :/

@dan-gamble
Copy link
Contributor

I'll give this a go Monday or if i find time this weekend while moving i'll give it a quick run :)

const env = require('@shopify/slate-env');
const {event} = require('@shopify/slate-analytics');

const promptContinueIfPublishedTheme = require('../prompts/continue-if-published-theme');
const promptSkipSettingsData = require('../prompts/skip-settings-data');
const promptDisableExternalTesting = require('../prompts/confim-private-ip');
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a typo on this file (confim => confirm)

@@ -56,8 +57,10 @@
"jest": "22.4.2",
"minimatch": "^3.0.4",
"minimist": "1.2.0",
"node-ip": "^0.1.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is meant to be "ip": "^1.1.5", or the prompts/confim-private-ip.js needs to have it's require() change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! Got mixed up there. Thanks.

@dan-gamble
Copy link
Contributor

Can't really fully test this on IE11 as i can't work out how to visit a :3001 address and accept the cert. Any JS file i go to prompts a download so i can't visit the page i want. No CSS files exist in development, images seem to be uploaded to CDN. Do you know of an asset i can visit to get this working?

@t-kelly
Copy link
Contributor Author

t-kelly commented Sep 4, 2018

@dan-gamble I gave IE11 a crack and everything seemed to work fine after visiting https://x.x.x.x:3000?preview_theme_id=xxxxxxxx. I didn't need to accept or navigate to any assets on the asset server port (3001).

@t-kelly t-kelly merged commit 6740b7e into master Sep 4, 2018
@t-kelly t-kelly deleted the add-browsersync branch September 4, 2018 15:00
@dan-gamble
Copy link
Contributor

I'll give it another go, awesome PR though @t-kelly. Thanks a ton for getting this in and prioritising it.

@lmartins
Copy link

lmartins commented Sep 12, 2018

Thanks so much for this feature @t-kelly this will be tremendously useful.
On IE11 and Edge, I still have issues where the assets are not loaded. I've tried the trick of opening an asset link directly, but for those browsers nothing seems to works and those requests are always rejected.
So excited to have this feature available in Slate! Thank you!

Update: One thing I'm noticing with beta 7, is that the refresh actually takes a few seconds more. While before it was pretty much instant, now it takes anything between 3 to 6 seconds for the browser to receive the updates.

@lock
Copy link

lock bot commented Oct 26, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants