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

remove jsdom for prod pipeline #192

Merged

Conversation

thescientist13
Copy link
Member

@thescientist13 thescientist13 commented Sep 10, 2019

Related Issue

resolves #138

Summary of Changes

  1. Removed "duplicate" serialization by removing JSDOM from the build pipeline.

Takes a nice chunk out of our dependency footprint

$ yarn why jsdom
yarn why v1.12.3
[1/4] 🤔  Why do we have the module "jsdom"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "[email protected]"
info Has been hoisted to "jsdom"
info This module exists because it's specified in "devDependencies".
info Disk size without dependencies: "3.12MB"
info Disk size with unique dependencies: "7.31MB"
info Disk size with transitive dependencies: "19.57MB"
info Number of shared dependencies: 51
✨  Done in 0.91s.

@thescientist13 thescientist13 added the chore unit testing, maintenance, etc label Sep 10, 2019
@thescientist13
Copy link
Member Author

As far as I can tell, the output is the same.

@hutchgrant
Copy link
Member

There was a specific reason for using jsdom, something did not serialize properly. Extra caution with this.

@thescientist13
Copy link
Member Author

There was a specific reason for using jsdom, something did not serialize properly.

What was it?

@@ -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 });
Copy link
Member

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.

Copy link
Member

@hutchgrant hutchgrant Sep 10, 2019

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.

Copy link
Member

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'})

Copy link
Member

@hutchgrant hutchgrant Sep 10, 2019

Choose a reason for hiding this comment

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

https://github.com/hutchgrant/ssr-evergreen-demo/blob/b18f31038dd24fb1e003ffdb00a18a20429e1d6c/renderer.js#L31

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.

Copy link
Member Author

@thescientist13 thescientist13 Sep 10, 2019

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.

Copy link
Member Author

@thescientist13 thescientist13 Sep 10, 2019

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.

Copy link
Member Author

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.

@thescientist13
Copy link
Member Author

going to repoint this to release branch to avoid issues with packaging changes due to monorepo

@thescientist13 thescientist13 changed the base branch from master to release/0.4.0 September 16, 2019 23:20
@thescientist13 thescientist13 force-pushed the chore/issue-138-remove-jsdom-build-pipeline branch from 8dc73a9 to 8be84fb Compare September 16, 2019 23:27
@thescientist13 thescientist13 merged commit 79c6fc3 into release/0.4.0 Sep 21, 2019
@thescientist13 thescientist13 deleted the chore/issue-138-remove-jsdom-build-pipeline branch September 21, 2019 18:40
thescientist13 added a commit that referenced this pull request Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore unit testing, maintenance, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants