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

clarification if context is public or private API #656

Closed
1 of 4 tasks
pieh opened this issue Jun 4, 2020 · 5 comments
Closed
1 of 4 tasks

clarification if context is public or private API #656

pieh opened this issue Jun 4, 2020 · 5 comments

Comments

@pieh
Copy link

pieh commented Jun 4, 2020

Documentation Is:

  • Missing
  • Needed
  • Confusing
  • Not Sure?

Please Explain in Detail...

When creating instance of middleware it provide object with methods that are documented as public API (like waitUntilValid, invalidate, close), but also it contains context which is not documented. It is used in "express-style" middleware internally, so it might be considered private API (or might be just not documented API that can be used publicly).

Your Proposal for Changes

Either explicitly clarify that context is considered private API and should not be relied on or add context related APIs to README (and potentially to @types/webpack-dev-middleware, but that's probably outside of the scope of this repo)


My motivation behind request for clarification:

In my proof of concept code I'm reaching to webpackDevMiddlewareInstance.context.watching to be able to suspend/resume webpack watching to control when webpack is "allowed" to recompile, but I'm not sure if I'm using private API (which can change any time) or not.

@alexander-akait
Copy link
Member

alexander-akait commented Jun 5, 2020

In my proof of concept code I'm reaching to webpackDevMiddlewareInstance.context.watching to be able to suspend/resume webpack watching to control when webpack is "allowed" to recompile, but I'm not sure if I'm using private API (which can change any time) or not.

Interesting use case, can you provide some real examples?

Honestly, I would have made it private. If you need something new for new ideas we can implement method for this.

I was wrong, it is public API, we need to document this

@pieh
Copy link
Author

pieh commented Jun 6, 2020

Interesting use case, can you provide some real examples?

This is for a feature I work on for gatsby, the code is not really ready/working yet, but the gist is that we have 2 quite separate services (we have more - but for this thing only 2 are relevant):

  • one for frontend source code (that's our webpack related things)
  • another one for data layer (which is separate from webpack)

Because those 2 are not interconnected right now they can run independently today and there is no need to coordinate them (we might sometimes get some unnecessary webpack recompilations, but right now they are at most "wasteful" and not breaking).

Feature I work on can be described as "data-driven code-splitting" and gist of it is that data can decide which stuff gets bundled (some information in gatsbyjs/gatsby#18689 ). The problem I'm facing now is that this feature introduce interdependencies between previously 2 isolated systems. If just gatsby internals were able to trigger changes that cause webpack recompilation I would be fine - but because user can invalidate (as in edit some frontend code) while other work is happening we could emit hot-update in rather unfortunate timing leaving user with temporarily weird/broken/inconsistent state (it will fix itself eventually on its own - but "damage" can be done already in browser, causing runtime errors there etc, providing just subpar DX). So idea here is to suspend/pause webpack when there is other work happening and resume when "idle" which should result in emitting updates at time points when we know everything else is processed which should (in my head at least right now) prevent broken states in browser.

@hiroppy
Copy link
Member

hiroppy commented Aug 17, 2020

This issue is already resolved?

@wardpeet
Copy link

Yes this whas been documented now and part of @types packaging so this is great!

@alexander-akait
Copy link
Member

Resolved

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

No branches or pull requests

4 participants