Closed pretzelhammer closed 1 year ago
Deployed Styleguide and Lab.Notes
File | Before | After |
---|---|---|
components/Modal/script.js |
10.2 kB |
8%β11.0 kB |
Total (Includes all files) | 1.7 MB |
0.7%β1.8 MB |
Tarball size | 331.3 kB |
1%β336.0 kB |
π€ This report was automatically generated by pkg-size-action
:tada: This PR is included in version 15.2.1 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Describe the problem this PR addresses
The bugs:
β (1) a beforeClose hook set via options would never run
One way to set a beforeClose hook was via the options object in the 2nd param of
modalApi.open
, e.g.This is bad obviously because the whole purpose of the beforeClose hook is to potentially block the modal from closing if the user forgot or failed to do something, but it would close regardless potentially leading to bad user experience or data in a corrupt or incomplete state. The beforeClose hook technically could also be used to perform final data clean up steps after a user was done interacting with a modal, and it failing to run could also lead to corrupt or incomplete data state.
Nobody noticed it was broken because... nobody was using it, which begs the question: why was it implemented in the first place π€·? It was likely used for a time, then dropped or refactored, and then broken in later commit.
β (2) setting a beforeClose hook via the Modal's
beforeClose
prop would overwrite the beforeClose hook set via optionsThis is a very subtle bug that no one would have ever likely noticed because of bug (1) but even if that bug was fixed in an earlier or later version of Maker then this bug would pop up, e.g.
β (3) calling the close function returned by
modalApi.open
would force close an entire stack of modals from the bottomCalling
modalApi.close
is suppose to only close the current modal, and if there is another modal stacked on top of the current modal then closing is blocked. This was correctly enforced formodalApi.close
but not correctly enforced for the close function returned frommodalApi.open
, e.g.Note: force closing a stack of modals from the bottom is not good because: the bottommost modal usually isn't aware of the state of the modals above it, and if the user is performing some action in the upper modals like filling out a form then randomly closing it on them is horrible user experience. This is why we encourage and attempt to enforce closing modals from the top only since the topmost modals have the most context and are the ones which are guiding the user experience.
β (4) calling the close function returned by
modalApi.open
would not run any beforeClose hooks on the closed modalβ (5) calling
modalApi.state.parentModal.close
no longer works, but even when it "worked" it was broken in the same way as described by bug (4)Originally
modalApi.state.parentModal.close
was implemented to close a stack of modals from the top. Since then it broke during some commit and stopped working, however even when it did "work" it was still broken in the same way as described by bug (4), i.e. none of the beforeClose hook would run.β (6) calling
modalApi.state.parentModal.close
would only close a stack of exactly 2 modals, but would break for any other number, e.g. 1 or 3+I think it's okay to want to close an entire stack of modals from the top. However, the way to do it should be reliable and independent regardless of how many modals there are in the stack, e.g. 1, 2, 3, 4 and so on. The original implementation of this feature only enabled users to close a stack of exactly 2 modals, and for any other number it was useless.
Describe the changes in this PR
The fixes:
β (1) beforeClose hook set via options now runs
β (2) beforeClose hook set via Modal's
beforeClose
prop no longer overwrites the beforeClose hook set via options, both are runBoth hooks have the opportunity to block closing. The hook set via props is run first and the hook set via options is run second. The hooks are run lazily, i.e. if the first hook blocks closing then the second hook isn't run.
β (3) calling the close function returned by
modalApi.open
will at most close the single specific opened modal, but will not close if there is a stack of multiple modalsIt's not possible to accidentally or unintentionally close a stack of modals from the bottom anymore, as the close function returned from
modalApi.open
will now only close that specific single opened modal, and if there are modals stacked on top of it then closing will fail and the function will returnfalse
, e.g.β (4) calling the close function returned by
modalApi.open
will run all beforeClose hooks registered on the opened modalβ (5) you can now call
modalApi.closeAll
to close an entire stack of modals from the top, and it will correctly run all of the beforeClose hooks on each modalβ (6) calling
modalApi.closeAll
works for closing a stack of modals of any sizemodalApi.closeAll
works for closing a single modal, or a couple modals, or 3, or 4, or so on.Other information
modalApi.state.parentModal.close
should be refactored to usemodalApi.closeAll
after this PR is merged & releasedcurrentLayer
toparentModalApi
because I felt that name is more descriptive