kirklin / celeris-web

Celeris Web is a highly performant and customizable front-end development template built with Vue 3, Vite, and TypeScript. It features the latest syntax, components and APIs auto importing, state management, Chinese font presets, internationalization, and integration with OpenAI's ChatGPT API.
https://celeris-web.vercel.app/
MIT License
384 stars 60 forks source link

Bug: Unable to Persist Themes Properly - Possible Issue with Pinia Initialization #3

Closed kirklin closed 1 year ago

kirklin commented 1 year ago

Describe the bug

Current Behavior: 当前行为:

Themes are not persisting as expected when using Pinia in the project. The problem seems to be related to the Pinia initialization process.

在项目中使用Pinia时,主题不能按预期持久化。问题似乎与Pinia的初始化过程有关。

Expected Behavior: 预期行为:

Themes should persist properly and be accessible throughout the application, even when used before Pinia is installed.

主题应该正确持久化,并在整个应用程序中可访问,即使在安装Pinia之前使用也是如此。

Steps to Reproduce: 重现步骤:

Install and set up Pinia in a project. 在项目中安装并设置Pinia。

Create a theme and set it using Pinia. 创建一个主题并使用Pinia进行设置。

Attempt to access the theme in a component or module that uses Pinia before Pinia is installed (e.g., using pinia.use before calling app.use(pinia)). 尝试在使用Pinia之前访问主题的组件或模块中(例如,在调用app.use(pinia)之前使用pinia.use)。

Code Snippet: 代码片段:

// Pinia Initialization
// Pinia 初始化
export function createPinia(): Pinia {
  // ...
  let _p: Pinia['_p'] = [];
  let toBeInstalled: PiniaPlugin[] = [];
  // ...

  const pinia: Pinia = markRaw({
    install(app: App) {
      setActivePinia(pinia);
      if (!isVue2) {
        // ...
        toBeInstalled.forEach((plugin) => _p.push(plugin));
        toBeInstalled = [];
      }
    },
    use(plugin) {
      if (!this._a && !isVue2) {
        toBeInstalled.push(plugin);
      } else {
        _p.push(plugin);
      }
      return this;
    },
    // ...
  });
  // ...
}

Additional Information: 附加信息:

It seems that when using Pinia before it is installed, the theme-related plugins are not properly added to the _p list, causing themes to not persist correctly. This issue may affect other functionalities that rely on plugins being correctly initialized during Pinia setup.

似乎在Pinia安装之前使用时,与主题相关的插件未正确添加到 _p 列表中,导致主题不能正确持久化。该问题可能会影响依赖于正确初始化插件的其他功能的运行,这在Pinia设置过程中可能会发生。

Potential Solution: 潜在解决方案:

One possible solution is to ensure that the necessary plugins are correctly added to the _p list, even when using Pinia before its installation. This might involve modifying the use method or the initialization process to handle scenarios where plugins are used before Pinia is installed.

一个可能的解决方案是确保在在Pinia安装之前使用时正确地将必要的插件添加到 _p 列表中。这可能涉及修改 use 方法或初始化过程,以处理在安装Pinia之前使用插件的情况。

Please investigate and address this issue to ensure proper theme persistence in projects using Pinia. Let me know if you need any additional information or assistance in resolving this problem.

Reproduction

-

System Info

-

Validations

kirklin commented 1 year ago

Link https://github.com/prazdevs/pinia-plugin-persistedstate/issues/217