Skip to content

updates example - catches the case whereby assets are an object #311

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

Merged
merged 3 commits into from Aug 20, 2018
Merged

updates example - catches the case whereby assets are an object #311

merged 3 commits into from Aug 20, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jul 2, 2018

What kind of change does this PR introduce?
Change to the SSR example in the README

Did you add tests for your changes?
tests not required

Summary
when following this example for SSR I added a check for the case in normalizeAssets whereby an object will be converted to an array. This makes sense for the purpose when your webpack entry is an object. Then you will get an array of paths.

Does this PR introduce a breaking change?
no

Other information
I'm not an expert and maybe there is an edge case where this method is unsuitable, but it works for my use case and would maybe help someone else too

@jsf-clabot
Copy link

jsf-clabot commented Jul 2, 2018

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Jul 5, 2018

Codecov Report

Merging #311 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #311   +/-   ##
=======================================
  Coverage   96.81%   96.81%           
=======================================
  Files           7        7           
  Lines         251      251           
=======================================
  Hits          243      243           
  Misses          8        8

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 27b6c1a...f9ab774. Read the comment docs.

README.md Outdated
@@ -318,7 +318,7 @@ const middleware = require('webpack-dev-middleware');

// This function makes server rendering of asset references consistent with different webpack chunk/entry configurations
function normalizeAssets(assets) {
if (typeof assets === 'object') {
if (Object.prototype.toString.call(assets) === '[object Object]') {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not a good change, as there are many different cases which qualify an entity as an object. you should recommend use of a module like is-plain-obj instead

Copy link
Author

Choose a reason for hiding this comment

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

@shellscape Yes I'm just realising this now, will change

Copy link
Member

Choose a reason for hiding this comment

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

isObject from lodash is okay, but it will make a big dependency. When checking object type i usually go for typeof assets === Object or assets instanceof Object

Copy link
Author

Choose a reason for hiding this comment

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

@ev1stensberg but the problem there is
image

Copy link
Author

Choose a reason for hiding this comment

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

either of those checks would catch arrays

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah just go with a package to make this example simple. we don't need to bikeshed over that, we just want something simple for users to consume in the docs. if they prefer another method, I'm sure they'll use it.

Copy link
Author

Choose a reason for hiding this comment

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

👍

311289189 added 3 commits July 6, 2018 06:42
@alexander-akait
Copy link
Member

@michael-ciniawsky same problem with tests here?

@michael-ciniawsky
Copy link
Member

Yes, it's a flake (we need to investigate separately) :) The docs update likely won't have had an effect here :D 😛

@alexander-akait alexander-akait merged commit e0c5f11 into webpack:master Aug 20, 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.

5 participants