OptimizedComponents.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact support@quantumnous.com
  14. */
  15. import React from 'react';
  16. import MessageContent from './MessageContent';
  17. import MessageActions from './MessageActions';
  18. import SettingsPanel from './SettingsPanel';
  19. import DebugPanel from './DebugPanel';
  20. // 优化的消息内容组件
  21. export const OptimizedMessageContent = React.memo(MessageContent, (prevProps, nextProps) => {
  22. // 只有这些属性变化时才重新渲染
  23. return (
  24. prevProps.message.id === nextProps.message.id &&
  25. prevProps.message.content === nextProps.message.content &&
  26. prevProps.message.status === nextProps.message.status &&
  27. prevProps.message.role === nextProps.message.role &&
  28. prevProps.message.reasoningContent === nextProps.message.reasoningContent &&
  29. prevProps.message.isReasoningExpanded === nextProps.message.isReasoningExpanded &&
  30. prevProps.isEditing === nextProps.isEditing &&
  31. prevProps.editValue === nextProps.editValue &&
  32. prevProps.styleState.isMobile === nextProps.styleState.isMobile
  33. );
  34. });
  35. // 优化的消息操作组件
  36. export const OptimizedMessageActions = React.memo(MessageActions, (prevProps, nextProps) => {
  37. return (
  38. prevProps.message.id === nextProps.message.id &&
  39. prevProps.message.role === nextProps.message.role &&
  40. prevProps.isAnyMessageGenerating === nextProps.isAnyMessageGenerating &&
  41. prevProps.isEditing === nextProps.isEditing &&
  42. prevProps.onMessageReset === nextProps.onMessageReset
  43. );
  44. });
  45. // 优化的设置面板组件
  46. export const OptimizedSettingsPanel = React.memo(SettingsPanel, (prevProps, nextProps) => {
  47. return (
  48. JSON.stringify(prevProps.inputs) === JSON.stringify(nextProps.inputs) &&
  49. JSON.stringify(prevProps.parameterEnabled) === JSON.stringify(nextProps.parameterEnabled) &&
  50. JSON.stringify(prevProps.models) === JSON.stringify(nextProps.models) &&
  51. JSON.stringify(prevProps.groups) === JSON.stringify(nextProps.groups) &&
  52. prevProps.customRequestMode === nextProps.customRequestMode &&
  53. prevProps.customRequestBody === nextProps.customRequestBody &&
  54. prevProps.showDebugPanel === nextProps.showDebugPanel &&
  55. prevProps.showSettings === nextProps.showSettings &&
  56. JSON.stringify(prevProps.previewPayload) === JSON.stringify(nextProps.previewPayload) &&
  57. JSON.stringify(prevProps.messages) === JSON.stringify(nextProps.messages)
  58. );
  59. });
  60. // 优化的调试面板组件
  61. export const OptimizedDebugPanel = React.memo(DebugPanel, (prevProps, nextProps) => {
  62. return (
  63. prevProps.show === nextProps.show &&
  64. prevProps.activeTab === nextProps.activeTab &&
  65. JSON.stringify(prevProps.debugData) === JSON.stringify(nextProps.debugData) &&
  66. JSON.stringify(prevProps.previewPayload) === JSON.stringify(nextProps.previewPayload) &&
  67. prevProps.customRequestMode === nextProps.customRequestMode &&
  68. prevProps.showDebugPanel === nextProps.showDebugPanel
  69. );
  70. });