-
Couldn't load subscription status.
- Fork 0
Closed
Description
Problem
Production mode encounters TypeRef resolution errors when rendering pages:
Error: a reference of type '@codelab/TypeRef' could not resolve an object with id '016048df-df67-4371-9979-6a4570f3ebb4'
This happens because:
- Production queries (
AtomProductionfragment) don't include theapifield to reduce payload size - The renderer code accesses atom API types using
.currentwhich throws when the reference can't be resolved - MobX initializes all computed properties even if they're not used, triggering TypeRef access
Root Causes Found
1. propsHaveErrors getter (line 177)
const schema = this.element.current.renderType.current.api.current.toJsonSchema({})- Only used in builder UI but MobX initializes it anyway
- Fixed by using
.maybeCurrentinstead of.current
2. renderedChildrenProp getter (line 176)
const atomApi = isAtom(this.element.renderType.current)
? this.element.renderType.current.api.current // ❌ Throws error
: undefined- Used to determine if atoms accept children props
- Fixed by using
.api.maybeCurrentinstead of.api.current
Solution Implemented
Changed all .current accesses to .maybeCurrent when accessing atom API types. This returns undefined instead of throwing when the reference isn't resolved.
Files Modified
-
libs/frontend/application/renderer/src/store/runtime-element.model.ts- Fixed
propsHaveErrorsgetter
- Fixed
-
libs/frontend/application/renderer/src/store/runtime-element-prop.model.ts- Fixed
renderedChildrenPropgetter
- Fixed
Long-term Recommendations
- Separate builder-specific logic from core runtime models
- Use
.maybeCurrentconsistently for optional references - Consider loading minimal type data in production (just field names for children detection)
- Add ESLint rule to warn about
.currentusage on type references
Related Discussions
- Deep Analysis: RootRenderer Render Cycle and Architecture #3759 - Deep Analysis: RootRenderer Render Cycle and Architecture
- Contains detailed analysis of why types are accessed in production