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

Determines whether PUBLIC_URL is same-origin before registering SW. #2432

Merged
merged 1 commit into from Jun 26, 2017

Conversation

Projects
None yet
4 participants
@jeffposnick
Copy link
Contributor

commented May 31, 2017

R: @Timer @gaearon
FYI: @addyosmani

This is a bit more explicit than trying to use a regular expression. It uses the URL object inside of a block that first checks to see if navigator.serviceWorker is defined; URL should always exist in browsers that support service workers.

From testing locally, I saw scenarios in which process.env.PUBLIC_URL wasn't set at all (which contradicts what @Timer suggested in the issue).

The code in this PR should behave properly regardless of whether it's unset, whether it's set to a local path, or whether it's set to a full URL.

Fixes #2374

@facebook-github-bot

This comment has been minimized.

Copy link

commented May 31, 2017

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact cla@fb.com if you have any questions.

@Timer

This comment has been minimized.

Copy link
Collaborator

commented Jun 2, 2017

From testing locally, I saw scenarios in which process.env.PUBLIC_URL wasn't set at all (which contradicts what @Timer suggested in the issue).

It should always be provided; it just may be blank. This is changing in the near future.

Either way; this code should work.

@Timer

This comment has been minimized.

Copy link
Collaborator

commented Jun 2, 2017

I'm guessing we will need to add url-polyfill for this?

Would it be better to use Node's url?

url.parse(url.resolve(window.location, process.env.PUBLIC_URL))
> url.parse(url.resolve('https://github.com/facebookincubator/create-react-app/pull/2432', 'http://google.com'))
Url {
  protocol: 'http:',
  slashes: true,
  auth: null,
  host: 'google.com',
  port: null,
  hostname: 'google.com',
  hash: null,
  search: null,
  query: null,
  pathname: '/',
  path: '/',
  href: 'http://google.com/' }

// --

> url.parse(url.resolve('https://github.com/facebookincubator/create-react-app/pull/2432', '/foo'))
Url {
  protocol: 'https:',
  slashes: true,
  auth: null,
  host: 'github.com',
  port: null,
  hostname: 'github.com',
  hash: null,
  search: null,
  query: null,
  pathname: '/foo',
  path: '/foo',
  href: 'https://github.com/foo' }
@jeffposnick

This comment has been minimized.

Copy link
Contributor Author

commented Jun 2, 2017

All browsers that support service workers support the URL object, and the code that uses the URL object is conditionally executed inside of a block that first checks for SW support. So it seemed safe to use the native URL here. I'm happy to throw in a 'URL' in window check if you'd feel better about that.

If we shouldn't use URL for some reason, I'd rather re-implement this using string comparisons than incur the cost of bringing in a polyfill or external library.

@Timer

This comment has been minimized.

Copy link
Collaborator

commented Jun 2, 2017

All browsers that support service workers support the URL object, and the code that uses the URL object is conditionally executed inside of a block that first checks for SW support.

Oops, I overlooked this. Great!

@jeffposnick jeffposnick referenced this pull request Jun 2, 2017

Open

wepback public path make index.html cache not working. #79

1 of 3 tasks complete

@gaearon gaearon added this to the 1.0.8 milestone Jun 26, 2017

@gaearon gaearon merged commit a7d31d9 into facebook:master Jun 26, 2017

1 of 2 checks passed

continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@gaearon

This comment has been minimized.

Copy link
Member

commented Jun 26, 2017

Thanks!

@gaearon gaearon referenced this pull request Jun 28, 2017

Merged

Changelog for 1.0.8 #2664

romaindso added a commit to romaindso/create-react-app that referenced this pull request Jul 10, 2017

wmonk referenced this pull request in wmonk/create-react-app-typescript Aug 7, 2017

morgs32 added a commit to BrickworkSoftware/create-react-app that referenced this pull request Sep 1, 2017

@jeffposnick jeffposnick deleted the jeffposnick:check-public-url-origin branch Sep 18, 2017

@lock lock bot locked and limited conversation to collaborators Jan 20, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.