Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apps/executeJS/src/features/execute-code/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ export const useExecutionStore = create<ExecutionState>()(
partialize: (state) => ({
result: state.result,
}),
onRehydrateStorage: () => (state, error) => {
if (error) {
console.error('hydration failed:', error);
// persist 실패 시 localStorage 정리
localStorage.removeItem('executejs-execution-storage');

return;
}

if (state) {
console.log('hydration success');
// 앱 재시작 시 실행 중이었던 상태를 초기화
state.setExecuting(false);
}
},
}
)
);
26 changes: 25 additions & 1 deletion apps/executeJS/src/pages/playground/playground-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,32 @@ import { OutputPanel } from '@/widgets/output-panel';
import { useExecutionStore } from '@/features/execute-code';
import { PlayIcon, StopIcon } from '@radix-ui/react-icons';

const getInitialCode = (): string => {
try {
const executionStorage = localStorage.getItem(
'executejs-execution-storage'
);

if (executionStorage) {
const parsed = JSON.parse(executionStorage);
const code = parsed?.state?.result?.code;

if (code) {
console.log('result from executionStorage:', code);

return code;
}
}
} catch (error) {
console.error('error from executionStorage:', error);
}

return 'console.log("Hello, ExecuteJS!");';
};

export const PlaygroundPage: React.FC = () => {
const [code, setCode] = useState('console.log("Hello, ExecuteJS!");');
// FIXME: tab이 여러개 생기거나 global store로 상태가 이동되면 수정되어야함
const [code, setCode] = useState(getInitialCode);
const {
result: executionResult,
isExecuting,
Expand Down