-
Notifications
You must be signed in to change notification settings - Fork 10
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
remove jsdom for prod pipeline #192
remove jsdom for prod pipeline #192
Conversation
As far as I can tell, the output is the same. |
There was a specific reason for using jsdom, something did not serialize properly. Extra caution with this. |
What was it? |
packages/cli/lib/browser.js
Outdated
@@ -12,12 +11,10 @@ module.exports = async (url, label, route, outputDirectory) => { | |||
|
|||
const renderer = new Renderer(browser); | |||
const result = await renderer.serialize(url); | |||
|
|||
// need url: https://github.com/jsdom/jsdom/issues/2005 | |||
const dom = new JSDOM(result.content, { url }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const dom = new JSDOM(``, {
url: "https://example.org/",
referrer: "https://example.com/",
contentType: "text/html",
includeNodeLocations: true,
storageQuota: 10000000
});
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".
Removing this line could potential cause issues related to path/url of resources. I do not know where specifically this was an issue previously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although from my cursory tests I haven't seen any issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the issue cited in the comment: jsdom/jsdom#2005
<style type="text/css">
@import url("/css/blok_add.css");
</style>
Cannot be parsed without the correct url. Although I do not see that error serializing in puppeteer, maybe because we don't have any examples of relative css imports.
With jsdom:
The problem can be solved by specifying the parameter url.
new JSDOM(html, {url: 'http://example.com'})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my previous SSR-demo which formed the basis of this code base, I previously had puppeteer serialize, then used JSDOM to manipulate dom, then serialized again.
Perhaps thats why we kept it? In case we needed to change dom post-serialization via puppeteer?
The resulting page can now be modified easily with anything you need to be done on the server via JSDOM, serialized, and sent back to the client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotta love unit tests 😌
As part of the PR that added that comment re: JSDOM, we also added unit tests specifically for @import
. This was for issue #134
All unit tests are still passing and the website preview is working so I think all the right checks and balances are in place, IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, removing an extra translation layer seems like the right move architecturally too. If we're already pre-rendering / serializing with a "real" browser, serializing it through a fake one on top of that seems unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said, if there are specific test cases we need to validate, please suggest them and I can look to see if they are being covered.
going to repoint this to release branch to avoid issues with packaging changes due to monorepo |
8dc73a9
to
8be84fb
Compare
Related Issue
resolves #138
Summary of Changes
Takes a nice chunk out of our
dependency
footprint