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

Add documentUrl option #12

Merged
merged 4 commits into from
Sep 4, 2018
Merged

Add documentUrl option #12

merged 4 commits into from
Sep 4, 2018

Conversation

hugmanrique
Copy link
Contributor

@hugmanrique hugmanrique commented Jun 30, 2018

Some libraries such as react-router or reach-router depend on the current window URL (returned by window.location, location.URL...) to determine which route to render.

This PR adds a documentUrl option which is passed to the JSDOM url option which has the following behavior according to their docs:

url sets the value returned by window.location, document.URL, and document.documentURI, and affects things like resolution of relative URLs within the document and the same-origin restrictions and referrer used while fetching subresources. It defaults to "about:blank".

The default value is undefined which will tell JSDOM to use the default about:blank which you cannot change inside the JSDOM instance.

@developit

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@hugmanrique
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@hugmanrique
Copy link
Contributor Author

@developit any updates?

@developit
Copy link
Collaborator

Hiya! Sorry about that - this looks great!

src/index.js Outdated
@@ -156,6 +156,10 @@ async function prerender (parentCompilation, request, options, inject, loader) {
// suppress console-proxied eval() errors, but keep console proxying
virtualConsole: new jsdom.VirtualConsole({ omitJSDOMErrors: false }).sendTo(console),

// `url` sets the value returned by `window.location`, `document.URL`...
// Useful for routers that depend on the current URL (such as react-router or reach-router)
url: options.documentUrl,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we fall back to a default of http://localhost here in order to fix #14?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I currently don't have internet, will change it once I get it fixed. Thanks for the review 😀

@developit developit merged commit 0e813b3 into GoogleChromeLabs:master Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants