修复打包后文件展示问题
This commit is contained in:
@@ -166,6 +166,7 @@ export const FileEditorEnhanced: React.FC<FileEditorEnhancedProps> = ({
|
||||
const monacoRef = useRef<Monaco | null>(null);
|
||||
const autoSaveTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const fileCheckIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const isApplyingContentRef = useRef(false);
|
||||
const unlistenRef = useRef<UnlistenFn | null>(null);
|
||||
|
||||
const fileName = filePath.split("/").pop() || filePath;
|
||||
@@ -250,6 +251,9 @@ export const FileEditorEnhanced: React.FC<FileEditorEnhancedProps> = ({
|
||||
|
||||
// 处理内容变化
|
||||
const handleContentChange = useCallback((value: string | undefined) => {
|
||||
if (isApplyingContentRef.current) {
|
||||
return;
|
||||
}
|
||||
console.log('[FileEditor] Content change detected, new length:', value?.length);
|
||||
if (value !== undefined) {
|
||||
setContent(value);
|
||||
@@ -263,6 +267,21 @@ export const FileEditorEnhanced: React.FC<FileEditorEnhancedProps> = ({
|
||||
}
|
||||
}
|
||||
}, [originalContent, language]);
|
||||
|
||||
// 确保 Monaco 模型与 React state 同步,避免初始不显示或切换文件后不同步
|
||||
useEffect(() => {
|
||||
const ed = editorRef.current;
|
||||
if (!ed) return;
|
||||
const model = ed.getModel();
|
||||
if (!model) return;
|
||||
const current = model.getValue();
|
||||
if (content !== undefined && current !== content) {
|
||||
console.log('[FileEditor] Syncing editor model from state');
|
||||
isApplyingContentRef.current = true;
|
||||
model.setValue(content);
|
||||
isApplyingContentRef.current = false;
|
||||
}
|
||||
}, [content, filePath]);
|
||||
|
||||
// 验证代码
|
||||
const validateCode = async (_code: string) => {
|
||||
@@ -1011,8 +1030,10 @@ export const FileEditorEnhanced: React.FC<FileEditorEnhancedProps> = ({
|
||||
) : (
|
||||
<div className="flex-1 min-h-0">
|
||||
<Editor
|
||||
key={filePath}
|
||||
height="100%"
|
||||
language={language}
|
||||
path={filePath}
|
||||
value={content}
|
||||
onChange={handleContentChange}
|
||||
onMount={handleEditorDidMount}
|
||||
|
@@ -74,8 +74,8 @@ export const Topbar: React.FC<TopbarProps> = ({
|
||||
const status = await api.checkClaudeVersion();
|
||||
setVersionStatus(status);
|
||||
|
||||
// If Claude is not installed and the error indicates it wasn't found
|
||||
if (!status.is_installed && status.output.includes("No such file or directory")) {
|
||||
// If Claude is not installed, prompt the selection/install dialog
|
||||
if (!status.is_installed) {
|
||||
// Emit an event that can be caught by the parent
|
||||
window.dispatchEvent(new CustomEvent('claude-not-found'));
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ class AnalyticsService {
|
||||
|
||||
// Default configuration - pulled from Vite environment variables
|
||||
this.config = {
|
||||
apiKey: import.meta.env.VITE_PUBLIC_POSTHOG_KEY || 'phc_YOUR_PROJECT_API_KEY',
|
||||
apiKey: (import.meta.env.VITE_PUBLIC_POSTHOG_KEY as string | undefined) || '',
|
||||
apiHost: import.meta.env.VITE_PUBLIC_POSTHOG_HOST || 'https://app.posthog.com',
|
||||
persistence: 'localStorage',
|
||||
autocapture: false, // We'll manually track events
|
||||
@@ -66,6 +66,11 @@ class AnalyticsService {
|
||||
|
||||
private initializePostHog(settings: AnalyticsSettings): void {
|
||||
try {
|
||||
// Guard: do not initialize PostHog without a valid API key
|
||||
if (!this.config.apiKey) {
|
||||
console.info('Analytics: PostHog not initialized (no API key provided)');
|
||||
return;
|
||||
}
|
||||
posthog.init(this.config.apiKey, {
|
||||
api_host: this.config.apiHost,
|
||||
capture_pageview: false, // Disable automatic pageview capture
|
||||
|
52
src/main.tsx
52
src/main.tsx
@@ -5,32 +5,54 @@ import { ErrorBoundary } from "./components/ErrorBoundary";
|
||||
import { AnalyticsErrorBoundary } from "./components/AnalyticsErrorBoundary";
|
||||
import { analytics, resourceMonitor } from "./lib/analytics";
|
||||
import { PostHogProvider } from "posthog-js/react";
|
||||
import { loader } from "@monaco-editor/react";
|
||||
import "./lib/i18n"; // 初始化国际化
|
||||
import "./assets/shimmer.css";
|
||||
import "./styles.css";
|
||||
|
||||
// Initialize analytics before rendering
|
||||
// Configure Monaco loader to use local assets (copied to /public/monaco/vs)
|
||||
try {
|
||||
loader.config({ paths: { vs: "/monaco/vs" } });
|
||||
} catch (e) {
|
||||
console.error("[Monaco] loader.config failed:", e);
|
||||
}
|
||||
|
||||
// Initialize analytics before rendering (will no-op if no consent or no key)
|
||||
analytics.initialize();
|
||||
|
||||
// Start resource monitoring (check every 2 minutes)
|
||||
resourceMonitor.startMonitoring(120000);
|
||||
|
||||
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
||||
<React.StrictMode>
|
||||
<PostHogProvider
|
||||
apiKey={import.meta.env.VITE_PUBLIC_POSTHOG_KEY}
|
||||
options={{
|
||||
api_host: import.meta.env.VITE_PUBLIC_POSTHOG_HOST,
|
||||
defaults: '2025-05-24',
|
||||
capture_exceptions: true,
|
||||
debug: import.meta.env.MODE === "development",
|
||||
}}
|
||||
>
|
||||
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
|
||||
const posthogKey = (import.meta as any).env.VITE_PUBLIC_POSTHOG_KEY as string | undefined;
|
||||
|
||||
if (posthogKey) {
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<PostHogProvider
|
||||
apiKey={posthogKey}
|
||||
options={{
|
||||
api_host: (import.meta as any).env.VITE_PUBLIC_POSTHOG_HOST,
|
||||
capture_exceptions: true,
|
||||
debug: import.meta.env.MODE === "development",
|
||||
}}
|
||||
>
|
||||
<ErrorBoundary>
|
||||
<AnalyticsErrorBoundary>
|
||||
<App />
|
||||
</AnalyticsErrorBoundary>
|
||||
</ErrorBoundary>
|
||||
</PostHogProvider>
|
||||
</React.StrictMode>
|
||||
);
|
||||
} else {
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<ErrorBoundary>
|
||||
<AnalyticsErrorBoundary>
|
||||
<App />
|
||||
</AnalyticsErrorBoundary>
|
||||
</ErrorBoundary>
|
||||
</PostHogProvider>
|
||||
</React.StrictMode>,
|
||||
);
|
||||
</React.StrictMode>
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user