Set flashMessages once per request instead of calling getMessages() ad hoc #7394
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of change
This PR changes the way flash messages are made available to Express controllers so that if there are any flash messages set on the response, they will automatically be propagated to Redux state through
res.locals.globalProps
.The problem with the current implementation was that flash messages wer read ad hoc with
res.locals.getMessages()
, which if called twice per request wipes out all messages. This PR replacesres.locals.getMessages()
withres.locals.flashMessages
, which can be read as many times as needed.The tests are also much simpler now as the existing tests were only testing whether message content of
'success:with-body'
messages was deserialized if it contained valid JSON and kept as is if not, but this functionality was baked into theuserLocals
middleware and could only be tested through that middleware. No other functionality of the middleware was tested, so I extracted the deserialization into a separate pure function which is trivial to test with no need for any mocks, spies or stubs.Test instructions
Everything should work as before