Skip to content

Fix loader context #135

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 1 commit into from
Nov 10, 2016
Merged

Conversation

jescalan
Copy link
Contributor

@jescalan jescalan commented Nov 9, 2016

This resolves a bug in which the webpack loader context was not being passed correctly to the options parsing function.

@ai
Copy link
Contributor

ai commented Nov 9, 2016

  1. Use PostCSS common config with ctx.webpack
  2. I will accept this PR only tomorrow (it is time to go to bed for me :) )

@jescalan
Copy link
Contributor Author

jescalan commented Nov 9, 2016

Not sure what you mean with #1 there, but thanks so much! Would be great to see a patch for this, it's breaking some of my software 😞

@ai
Copy link
Contributor

ai commented Nov 9, 2016

Loader options are deprecated (because of webpack bug).

Config: https://github.com/postcss/postcss-loader#usage

Webpack instance: https://github.com/postcss/postcss-loader#dynamic-config

@jescalan
Copy link
Contributor Author

jescalan commented Nov 9, 2016

Not entirely sure I understand why this would be the case. Either way, the ctx coming in was the node global previously, not the webpack loader context, which I assume wasn't the desired result!

@ai
Copy link
Contributor

ai commented Nov 9, 2016

webpack loader context is in ctx.webpack. ctx is not node global context. It is a argument for PostCSS common config:

module.exports = function (ctx) {

@ai
Copy link
Contributor

ai commented Nov 9, 2016

Here is more docs about ctx in PostCSS common config https://github.com/michael-ciniawsky/postcss-load-config#context

@jescalan
Copy link
Contributor Author

jescalan commented Nov 10, 2016

So I am not sure what postcss-load-config is, but I am not interested is using it at all here. I just need to get the webpack loader context available in a config function passed directly to the loader. Right now, that context is not available at all, you can trace it as such:

At this point, in the direct context of the exported function called by webpack, this is the webpack loader context. You save it off as a variable called loader. Now we move through the code, and here is where the parseOptions function is called without setting the context to anything specifically, so it retains its own context for this, and we have lost the webpack loader context.

Now, when we're inside parseOptions is when the config function is called, if one was passed. It gets called with this, which is set to the global context since there is no this bound to the function when its called -- the function is called without context, so it is automatically the global context. So inside of the config function passed in, it's the global context. This is a this/context bug in this specific codebase, it doesn't have anything to do with webpack at all, and is completely and entirely fixed by this PR alone.

The bug was introduced in this commit, when the options function call was extracted into a different file which didn't have the correct loader context.

Hope this makes sense!

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Nov 10, 2016

@ai like @jescalan said this inside parseOptions is not bound to loader, likely that is the source of a few weird bugs, we recently experienced :).

@jescalan 👍

@michael-ciniawsky michael-ciniawsky merged commit f27d12b into webpack-contrib:master Nov 10, 2016
@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Nov 10, 2016

@ai updated CHANGELOG.md and package.json locally, can you approve patch release on npm please ? :)

@ai
Copy link
Contributor

ai commented Nov 10, 2016

I told that I am sleeping 😉

I anyway planned to merge it and release tomorrow.

@michael-ciniawsky
Copy link
Member

I told that I am sleeping 😉

You're sleeping as it seems 😛 , but sry I didn't see it, not to make any stress here, can I push CHANGELOG and pkg version bump with 'Release 1.1.1 version' or better you do it tomorrow :)?

@ai
Copy link
Contributor

ai commented Nov 10, 2016

I will do it tomorrow

@michael-ciniawsky
Copy link
Member

But can't make npm patch release anyways. Sleep well

@ai kk discared

@ai
Copy link
Contributor

ai commented Nov 10, 2016

@jescalan released as 1.1.1.

But note, that loader options was deprecated ;).

@jescalan
Copy link
Contributor Author

@ai @michael-ciniawsky thanks so much guys for the quick response and release! 🎉

@ai
Copy link
Contributor

ai commented Nov 10, 2016

Thank you for fix :)

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