alibaba / ice

🚀 ice.js: The Progressive App Framework Based On React(基于 React 的渐进式应用框架)
https://ice.work
MIT License
17.83k stars 2.09k forks source link

页面级Store使用报错: Cannot read properties of null (reading 'store') #5947

Open aak1247 opened 1 year ago

aak1247 commented 1 year ago

Describe the bug

使用页面级store,会报错: Uncaught TypeError: Cannot read properties of null (reading 'store') at Object.useSelector (useSelector.js:126) at useModelState (modelApis.js:28) at Object.useModel (modelApis.js:23) at TerminalManage (TerminalManage.tsx:11) // 这里是实际发生调用的位置 at renderWithHooks (react-dom.development.js:14985) at updateFunctionComponent (react-dom.development.js:17356) at mountLazyComponent (react-dom.development.js:17677) at beginWork (react-dom.development.js:19055) at HTMLUnknownElement.callCallback (react-dom.development.js:3945) at Object.invokeGuardedCallbackDev (react-dom.development.js:3994)

相同项目,使用应用级(全局)store可以正常使用。store文件的后缀名都是.ts,app和页面的后缀名都是tsx

版本信息: "ice.js": "^2.6.6",

Expected behavior

期望能够正常使用页面级store

Actual behavior

No response

Version of ice.js

2.6.6

Content of build.json or ice.config.mts

{
  "plugins": [
    [
      "build-plugin-icestark",
      {
        "umd": true,
        "type": "child"
      }
    ],
    [
      "build-plugin-fusion",
      {
        "themePackage": "@alifd/theme-design-pro"
      }
    ],
    [
      "build-plugin-moment-locales",
      {
        "locales": ["zh-cn"]
      }
    ],
    [
      "build-plugin-antd",
      {
        "themeConfig": {
          "primary-color": "#1A59E9",
          "error-color": "#DC5A51"
        }
      }
    ]
  ],
  "babelPresets": [["@babel/preset-react", { "runtime": "automatic" }]],
  "router": {
    "lazy": true
  },
  "eslint": true,
  "store": true,
  "dropLogLevel": "log",
  "minify": {
    "type": "esbuild",
    "options": {
      "css": true
    }
  },
}

Additional context

No response

aak1247 commented 1 year ago

node版本 16.13

luhc228 commented 1 year ago

提供可复现的 demo

zhangfujin commented 1 year ago
import Layout from '@/layouts/index';
import Home from '@/pages/Home';
import About from '@/pages/About';

export default [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/',
        exact: true,
        component: Home
      },
      {
        path: '/about',
        component: About,
        pageConfig: {
          title: 'About'
        }
      },
    ]
  }
];

使用的页面必须是一级 ( "/" ) 路由下的 children (即: 二级路由)