[Bug]: Decode functionality in the Base64 Encoder/Decoder tool does not work. #259
Conversation
✅ Deploy Preview for freedevtool ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where the decode functionality in the Base64 Encoder/Decoder tool was broken. The issue was caused by problematic state management logic that interfered with the decode operation.
Key changes:
- Initialize the encoded text state with the default encoded value instead of an empty string
- Remove auto-reset logic that was preventing users from typing in the encoded field and decoding
- Remove unnecessary useEffect hook that encoded on mount (now handled by initial state)
Comments suppressed due to low confidence (1)
client/src/pages/tools/base64-encoder.tsx:74
- The
handleResetfunction setsencodedTextto an empty string, but the initial state now usesDEFAULT_BASE64_ENCODED. For consistency, the reset function should restore the state to match the initial state:
const handleReset = () => {
setPlainText(DEFAULT_BASE64);
setEncodedText(DEFAULT_BASE64_ENCODED);
setError(null);
};This ensures that clicking "Reset" returns the component to the exact same state as when it first loads.
const handleReset = () => {
setPlainText(DEFAULT_BASE64);
setEncodedText("");
setError(null);
};
| const handleEncodedTextChange = (value: string) => { | ||
| setEncodedText(value); | ||
| if (plainText !== DEFAULT_BASE64) { | ||
| setPlainText(DEFAULT_BASE64); | ||
| } | ||
| }; |
There was a problem hiding this comment.
The decode functionality fix lacks test coverage. Similar tools in the repository (e.g., json-yaml-converter.spec.ts, url-encoder.spec.ts) have comprehensive e2e tests that verify their encode/decode behavior. Consider adding tests to tests/e2e/tools/base64.spec.ts that verify:
- The encode button correctly encodes plain text to Base64
- The decode button correctly decodes Base64 to plain text
- The default values are displayed correctly on load
- The reset button works correctly
This will help prevent regression of the bug that was just fixed.
[Bug]: Decode functionality in the Base64 Encoder/Decoder tool does not work.
#136
Pull Request
📋 Description
🔧 Type of Change
📱 Screenshots/Videos
📝 Checklist
🔗 Related Issues
📋 Additional Notes