Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements code persistence functionality by restoring the last executed code from localStorage when the playground page is loaded. It also adds hydration error handling for the Zustand store.
- Added
getInitialCode()function to retrieve previously executed code from localStorage - Implemented
onRehydrateStoragecallback to handle hydration errors and reset execution state on app restart - Updated initial state of code editor to use persisted code instead of default "Hello, ExecuteJS!" message
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| apps/executeJS/src/pages/playground/playground-page.tsx | Added getInitialCode() function to restore code from localStorage and updated useState initialization to use it |
| apps/executeJS/src/features/execute-code/model.ts | Added onRehydrateStorage callback to handle hydration errors and reset execution state on app restart |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const getInitialCode = (): string => { | ||
| try { | ||
| const executionStorage = localStorage.getItem( | ||
| 'executejs-execution-storage' |
There was a problem hiding this comment.
The storage key 'executejs-execution-storage' is duplicated between this file and model.ts. Consider extracting it to a shared constant to maintain consistency and avoid potential mismatches.
| const getInitialCode = (): string => { | |
| try { | |
| const executionStorage = localStorage.getItem( | |
| 'executejs-execution-storage' | |
| const EXECUTION_STORAGE_KEY = 'executejs-execution-storage'; | |
| const getInitialCode = (): string => { | |
| try { | |
| const executionStorage = localStorage.getItem( | |
| EXECUTION_STORAGE_KEY |
| if (error) { | ||
| console.error('hydration failed:', error); | ||
| // persist 실패 시 localStorage 정리 | ||
| localStorage.removeItem('executejs-execution-storage'); |
There was a problem hiding this comment.
The storage key 'executejs-execution-storage' is hardcoded here but already defined at line 65. Reference the existing 'name' property from the persist configuration or extract to a constant to avoid duplication.
| const code = parsed?.state?.result?.code; | ||
|
|
||
| if (code) { | ||
| console.log('result from executionStorage:', code); |
There was a problem hiding this comment.
Console.log statements should be removed from production code or replaced with a proper logging mechanism. Consider removing this debug log or using a conditional logger.
| console.log('result from executionStorage:', code); |
| } | ||
|
|
||
| if (state) { | ||
| console.log('hydration success'); |
There was a problem hiding this comment.
Console.log statements should be removed from production code or replaced with a proper logging mechanism. Consider removing this debug log or using a conditional logger.
| console.log('hydration success'); |
ㅁㄴㅇㄹ