-
Notifications
You must be signed in to change notification settings - Fork 27
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
feat: withDevTools disabled in prod - tree-shaking docs #94
feat: withDevTools disabled in prod - tree-shaking docs #94
Conversation
Thanks @marcindz88. In the meantime, I've looked up the approach of the NgRx Devtools. The approach for tree-shaking is very similar to what you proposed, namely, using the environment files. Disabling it with What if we provide Time traveling is unavailable at the moment, so it would not have an immediate effect. Users could use the extension like
And the signature could be type Options = {
logOnly: boolean
}
withDevtools(name: string, options: Options = {logOnly: false); |
@rainerhahnekamp Yeah I was thinking, that some users may want to enable devtools in some prod-optimized environments like test staging. However I don't really like repeating the configuration in every store in app. Does this feature work in injection context? If yes maybe we could provide a provider that creates an injection token with global ngrx-toolkit configuration? |
You are right, I am all for an "injection" token approach. This would also fix the issue with one store having
Btw, why do you disable dev tools in a production environment? I always found it extremely helpful for debugging and reproducing issues that only occur in production. It is not that we are exposing any secrets. Anyone can monitor the network requests and—with a little bit of work—find out what's going on by looking at the minimized Javascript files. Just curious to learn something new here. |
I think there are several arguments for disabling / removing it in production:
Do you think we should add one configuration token for the whole library or a per-feature approach? |
Thanks for the detailed explanation. I suggest we go with one global configuration token. It should be just on or off |
@rainerhahnekamp please take a look. I have observed while testing that the store does not disconnect after application restart, I think this is because connect observer is not unsubscribed nor is disconnect called anywhere FYI https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Methods.md#disconnect. Also, I was thinking and we could use the pattern of overriding action creators to be able to detect action dispatches without the use of |
a114fda
to
054b3e7
Compare
@rainerhahnekamp please also take a look at this experiment: 1c7ee5d |
@marcindz88 thanks, I have another branch that deals with disconnection issues and some other stuff but haven't found the time to push it yet. I'll also checkout the automatic action name detection change, although I still think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work so far
@@ -87,7 +88,8 @@ export function withDevtools<Input extends EmptyFeatureResult>( | |||
): SignalStoreFeature<Input, EmptyFeatureResult> { | |||
return (store) => { | |||
const isServer = isPlatformServer(inject(PLATFORM_ID)); | |||
if (isServer) { | |||
const { logOnly } = inject(DEVTOOLS_CONFIG, { optional: true }) || DEFAULT_DEVTOOLS_CONFIG; | |||
if (isServer || logOnly) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logOnly
doesn't have an effect at the moment. Logging still happens but features like time travelling will be disabled.
Since we "only" have logging at the moment, we can leave this condition with isServer
only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if we should include this config for now. Maybe let's stash it for later (when it will do something) and merge only the tree-shaking docs ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with merging only the docs
* @returns The provider of the custom configuration. | ||
*/ | ||
export const provideStoreDevtoolsConfig = (config: Partial<DevtoolsConfig>) => { | ||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to make that as an environment provider so that it could only be called in the root scope or in paths?
What about override protection? I think that would also be useful.
@rainerhahnekamp regarding my experiment version: It is not only about the actionName, we should also pass action payload to redux extension. Also, we could prefix the action name with [name of store] and possibly change camelcase to a more readable version. |
@marcindz88 In order to get only the documentation part merged, could you please remove all files except the README from your PR? |
f7faad6
to
9b2fc3a
Compare
@rainerhahnekamp PR updated, I also added an a stub const for easier use in the environment file. Let me know if that's ok. |
9b2fc3a
to
067be79
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful, I just left a small comment on a stylistic issue but then we are ready to go.
README.md
Outdated
} | ||
``` | ||
|
||
Then all you need to do is replace `withDevTools` everywhere in your app with `environment.storeWithDevTools` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it is possible to update the example with a utility function which encapsulates the access to environment?
I don't think it is a good idea if we promote spreading access to the environment in the codebase.
So something like
function withTreeShakableDevTools(featureName: string) {
return environment.storeWithDevTolls(featureName);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added an exported const which lets us not to import environment file directly, and allows for keeping the function signature internal to the library (may be useful if there were changes)
…lity function update
Thanks again @marcindz88 |
Solution to #53