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
Allow disabling warning on exit in development #1176
Conversation
Size Change: -41.7 kB (5%) ✅ Total Size: 826 kB
ℹ️ View Unchanged
|
I agree with this DX improvement, it's a pain sometimes haha. But the inconsistency created between environments concerns me a bit too, once the UX step created when the user needs to leave the page with any pending stuff is important, which with this change, will not be validated always while developing. WDYT @merapi ? |
I think it's okay in dev mode (we know how it works and it's more for the end-user). |
return setPreventUnload; | ||
} | ||
|
||
export default usePreventWindowUnload; | ||
const isDevelopment = process.env.NODE_ENV === 'development'; |
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'm generally ok with this, but I also think that for a short while this would be useful to spot the history bugs which we had a few. Maybe we can wait for a bit before applying this change?
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.
There should be reliable tests in place at least to ensure that this works as expected before implementing this.
I personally definitely prefer my local env to be a copy of the production even if it's a bit annoying. Perhaps there should be a separate variable for disabling this in dev environment which would be off by default but could be turned on for the devs who prefer that.
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'll also keep it on - I don't mind it.
But we can simply change these lines to:
const shouldDisablePrevent = Boolean(process.env.DISABLE_PREVENT);
export default shouldDisablePrevent ? () => {} : usePreventWindowUnload;
And then you can just run DISABLE_PREVENT=1 npm run dev
locally if you want to prevent it? Would that be sufficient for your usecase, @merapi?
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.
Agree, .env/env var is the way to go here.
Codecov Report
@@ Coverage Diff @@
## master #1176 +/- ##
============================================
+ Coverage 52.23% 57.82% +5.59%
+ Complexity 241 215 -26
============================================
Files 461 528 +67
Lines 7710 8702 +992
============================================
+ Hits 4027 5032 +1005
+ Misses 3683 3670 -13
|
return setPreventUnload; | ||
} | ||
|
||
export default usePreventWindowUnload; | ||
const shouldDisablePrevent = Boolean(process.env.DISABLE_PREVENT); |
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.
Would be good to document it somewhere. WDYT? Maybe under the docs folder creating an ENV_VARS.md
file?
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.
Added some info in 3b4c007
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.
LGMT with one nit.
@@ -83,6 +83,10 @@ To get a production build, run: | |||
npm run build:js | |||
``` | |||
|
|||
### Live reload | |||
|
|||
We don't provide it OOTB. You can setup your own solution and `DISABLE_PREVENT=1 npm run dev` will help you with unwanted `beforeunload` alert. |
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.
IMHO, =true
/=false
are more natural.
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.
It's cast to bool in the code, so it's just the docs that'd need update.
Will do that in #1476
* master: (53 commits) Inline text formatting (#1323) Bump terser-webpack-plugin from 2.3.6 to 3.0.1 (#1597) Allow disabling warning on exit in development (#1176) fixing indent that was missed by automation Deploy plugin bundle to wiki repo for easier QA (#1590) Fix initial height of preset panel (#1591) Fixes editor resizing after fullbleed (#1553) More error handling Fix file drag & drop crash for unsupported media types (#1431) Improve test Bump polished from 3.6.1 to 3.6.2 (#1577) Bump react-transition-group from 4.3.0 to 4.4.0 (#1565) Remove Delete Page shortcut tooltip (#1574) renaming filteredStories to just stories. they are not filtered. updating typeahead input and options for new designs. New colors, tighter space, different expanded view. Removing option to filter internally through typeahead since we do all of that outside of the component. some styled component cleanup Remove wp element. Bump @testing-library/dom from 7.2.2 to 7.3.0 (#1563) Remove wp element Lints in tests Add more tests ...
* master: (109 commits) Inline text formatting (#1323) Bump terser-webpack-plugin from 2.3.6 to 3.0.1 (#1597) Allow disabling warning on exit in development (#1176) fixing indent that was missed by automation Deploy plugin bundle to wiki repo for easier QA (#1590) Fix initial height of preset panel (#1591) Fixes editor resizing after fullbleed (#1553) More error handling Fix file drag & drop crash for unsupported media types (#1431) Improve test Bump polished from 3.6.1 to 3.6.2 (#1577) Bump react-transition-group from 4.3.0 to 4.4.0 (#1565) Remove Delete Page shortcut tooltip (#1574) renaming filteredStories to just stories. they are not filtered. updating typeahead input and options for new designs. New colors, tighter space, different expanded view. Removing option to filter internally through typeahead since we do all of that outside of the component. some styled component cleanup Remove wp element. Bump @testing-library/dom from 7.2.2 to 7.3.0 (#1563) Remove wp element Lints in tests Add more tests ...
Don't warn on exit in development because It is a bit annoying (especially when you use auto-reload).
+
isDevelopment
variable narrow down to development only (we have production/test/development?).