Skip to content

docs(guides): fix HMR Gotcha section snippet (#1463) #1464

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 5 commits into from
Aug 1, 2017
Merged

docs(guides): fix HMR Gotcha section snippet (#1463) #1464

merged 5 commits into from
Aug 1, 2017

Conversation

maheshpec
Copy link
Contributor

@maheshpec maheshpec commented Jul 30, 2017

Fix for snippet in the Gotcha section of Hot Module Replacement Guide.

Resolves #1461

@skipjack
Copy link
Collaborator

skipjack commented Jul 30, 2017

@maheshpec does this resolve the issue you opened, #1463? Also, I think your issue may overlap with #1461 so I may close yours in favor of the first but I will double check before doing so.

Copy link
Collaborator

@skipjack skipjack left a comment

Choose a reason for hiding this comment

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

I think maybe we should re-organize this whole code block a bit -- typically if (module.hot) statements are found at the bottom of modules. Also, in this case I think it makes more sense logically to include it at the bottom of the file as it's dependent on previously defined variables and runs after the other code in the file.

cc @sbaidon @TheDutchCoder

@skipjack
Copy link
Collaborator

See my comment above... I think we can make a few changes to put the confusion to bed and make the code snippets flow a bit better.

@sbaidon can you explain more what those other warnings mentioned in #1461 were about? You mentioned some change to the entry configuration fixed them?

@sbaidon
Copy link
Contributor

sbaidon commented Jul 30, 2017

Ok, so I re-organized the block as @skipjack mentioned. I am not getting any kind of error, but the warning is still showing up:

screen shot 2017-07-30 at 12 05 00 pm

As you can see the print.js module is being updated, but then the warning is telling us it wasn't ?

My guess was that somehow webpack was trying to update the module twice, and it is only being accepted the first time.

I thought it had something to do with having both print.js and index.js listed as entry points in our configuration.

So when I removed print.js as an entry this is the output I got:

screen shot 2017-07-30 at 12 27 00 pm

By the way I added the new webpack.NamedModulesPlugin() plugin to the config so we could see names instead of ids.

Still not sure if I am doing anything else wrong...

@maheshpec
Copy link
Contributor Author

I think @sbaidon is right. It is trying to load it twice - once for the index and other for the print entry point. When its trying to load the print entry point, it is getting unaccepted in getAffectedStuff function within hotApply function of HotModuleReplacement.runtime.js file within webpack (I'm using 3.4.1). The exact condition is

if(module.hot._main) {                                                                                  
        return {                                                                                                           
          type: "unaccepted",                                                                                                        
          chain: chain,                                                                                                    
          moduleId: moduleId                                                                                               
        };                                                                                                                 
} 

IMHO the approach to fix would be to add a Preparation section which removes the print entry point. Please let me know what you guys think

@maheshpec
Copy link
Contributor Author

I made the changes that @sbaidon mentioned and the ones about ordering that @skipjack mentioned. I've tested this with 3.4.1 version of webpack and it is working without any console warnings for me.

@skipjack
Copy link
Collaborator

@maheshpec @sbaidon yes good catch and @maheshpec thank you for updating!

I should've caught that earlier, you shouldn't have an entry file that's consumed by another module without using the CommonsChunkPlugin and even there it usually just makes sense for vendor code splitting -- I completely missed that that was going on in these examples. I do understand how it happened when trying to synchronize this with the previous guides though. If we wanted to split print.js out to a separate chunk in the current setup, then import() would be a better solution.

As soon as the build passes, I'll get this merged so we can close out #1461.

@@ -94,6 +88,13 @@ __index.js__
}

document.body.appendChild(component());
+
Copy link
Contributor

Choose a reason for hiding this comment

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

There's just this extra plus sign left

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that's ok, it's just indicating that a new line was added in between the last line of the script and new content. That's how we've done it in the other guides as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah or maybe you meant there's two plus signs? That's actually just a looking at a diff within a diff issue 😆 (there's really only one in the document).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a little confusing to view these diffs :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah like some kind diff inception lol

Copy link
Contributor

Choose a reason for hiding this comment

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

oh I did mean that the new line was added, but if that's how it has been done on the other guides is fine 👍

@skipjack skipjack merged commit 6e3d072 into webpack:master Aug 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants