Thorium is split into separate Webpack/Electron runtime bundles. Treat each bundle as an isolated runtime island. Runtime code must not import source from another runtime directly. Shared contracts, types, actions, and utilities must be moved to a common/shared area first.
Type-only imports count as imports for this rule: if two runtimes need the same type, the type belongs in common code.
New Thorium-owned code used by more than one runtime should go in one of these common areas:
src/common/**: runtime-neutral app contracts, models, IPC definitions, Redux action/state types, and utilities that do not depend on DOM, React, or Electron renderer APIs.src/renderer/common/**: renderer-only shared React, DOM, keyboard, hook, component, and Redux glue code.src/utils/**: small generic helpers that stay runtime-safe.
Existing shared/support areas:
src/renderer/reader/pdf/common/**are PDF-specific shared code used by the reader-side PDF host and the PDF webview.src/r2-xxx-js/**andsrc/third_party/**are vendored/support dependency code. Do not add Thorium runtime glue there just to bypass runtime boundaries.src/resources/**,src/typings/**, and asset/style imports may be shared where the relevant Webpack config allows them.
- Prefer
undefinedovernullfor absent optional values when the existing type or runtime contract allows it.
src/main.tsandsrc/main/**may importsrc/common/**,src/utils/**, and vendored/support dependencies. They must not importsrc/renderer/**.src/renderer/library/**may import library-owned files,src/common/**,src/renderer/common/**,src/utils/**, assets/styles/resources, and vendored/support dependencies. It must not importsrc/renderer/reader/**orsrc/main/**.src/renderer/reader/**may import reader-owned files,src/common/**,src/renderer/common/**,src/utils/**, assets/styles/resources, and vendored/support dependencies. It must not importsrc/renderer/library/**,src/main/**, orsrc/renderer/reader/pdf/webview/**.src/renderer/reader/pdf/webview/**may import PDF webview-owned files, PDF-specific shared files, and vendored/support dependencies. Keep it independent from app renderer React components, app renderer Redux code,src/main/**, and general Thorium common modules unless the Webpack scope rules are intentionally changed.src/r2-xxx-js/r2-navigator-js/electron/renderer/webview/preload.tsmust stay isolated from Thorium app runtimes. It should not importsrc/main/**,src/renderer/library/**, reader React/Redux modules, or Thorium common/resources/typings unless the preload Webpack scope rules are intentionally changed.
The current runtime separation is enforced during Webpack builds by scripts/webpack-loader-scope-checker.js:
webpack.config.main.jsforbidssrc/renderer.webpack.config.renderer-library.jsforbidssrc/renderer/readerandsrc/main.webpack.config.renderer-reader.jsforbidssrc/renderer/library,src/main, andsrc/renderer/reader/pdf/webview.webpack.config.renderer-pdf.js,webpack.config.renderer-pdf-extract.js, andwebpack.config.preload.jsapply stricter webview/preload isolation rules.
When changing a boundary, update the relevant Webpack config and this file together. After touching imports across runtime-adjacent code, run the relevant Webpack config so the scope checker can catch direct runtime-to-runtime imports.
