You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
site generate: detail and list pages fail tsc (TS6133) for an entity whose fields are all relations; formatFieldValue and isEmpty are emitted unconditionally #196
site generate produces detail.generated.tsx and list.generated.tsx files that fail tsc -b with TS6133 when every field of an entity renders without the generic formatter. The main case is a join entity whose fields are all to-one relations to targets that have @display. The detail template always imports formatFieldValue and always declares isEmpty, but only the composite branch and the generic fallback branch use them. The relation-link and file branches use neither. The list template has the same problem with its formatFieldValue import: relations default to @list(hidden), so an all-relation entity with no @list hints gets a list page with only the ID column and an unused import. The scaffold's tsconfig.json sets noUnusedLocals, so pnpm build fails as generated.
This is the same class of problem as #43 (which gated the Link import and the form parameter), for symbols that are still emitted unconditionally.
Version checked
v0.45.0 release binary (x86_64 Linux, PostgreSQL build), source at tag v0.45.0 (10ec403).
Reproduction
@display("name")
schema Product {
name: text required
}
@display("title")
schema Order {
title: text required
}
schema OrderLine {
order: -> Order required
product: -> Product required
}
schemaforge site generate -s schemas -o app
cd app && pnpm install && pnpm build
Actual:
src/app/pages/order-line/detail.generated.tsx(15,1): error TS6133: 'formatFieldValue' is declared but its value is never read.
src/app/pages/order-line/detail.generated.tsx(21,10): error TS6133: 'isEmpty' is declared but its value is never read.
src/app/pages/order-line/list.generated.tsx(12,1): error TS6133: 'formatFieldValue' is declared but its value is never read.
ELIFECYCLE Command failed with exit code 2.
With @list(primary) on product, the list page compiles (the primary cell calls formatFieldValue), but the detail page still fails. Both files are Owned (rewritten on every run), so they cannot be fixed in place. The only workaround is a --templates-dir override of the template.
Expected
The scaffold builds for any valid schema set, including join entities that hold only relations, and entities that hold only file fields.
They are used only at :64 (composite sub-fields) and :151-154 (the generic else branch). The file branch (:82-101) and the relation_one / relation_many branches with a display field (:102-145) use neither.
crates/schema-forge-cli/templates/site/src/app/pages/list.generated.tsx.jinja:11 imports formatFieldValue unconditionally. It is used only for a non-enum primary cell (:90) and the generic column cell (:145). context.rs:399-404 defaults every relation, file, composite, array, JSON and rich-text field to hidden.
crates/schema-forge-cli/src/commands/site/context.rs:145-163: has_relation_link and has_file_field already gate the Link and AttachmentDownload imports for the same noUnusedLocals reason. There is no equivalent flag for these two.
crates/schema-forge-cli/src/commands/site/vendor.rs:654: the scaffolded tsconfig.json sets "noUnusedLocals": true.
Add three flags to EntityView, next to has_relation_link:
uses_formatter: any field is composite, or reaches the else branch (anything except file, and except a relation with relation_display_field).
uses_is_empty: any field reaches the else branch.
list_uses_formatter: any field reaches the list's non-enum primary cell or its generic column cell.
Then gate the imports and the helper on them in both templates. Add a site_generate.rs test that runs the generator on an all-relation entity (with and without @list hints) and on an all-file entity, and asserts that the output passes tsc --noEmit or at least contains none of the unused symbols.
Summary
site generateproducesdetail.generated.tsxandlist.generated.tsxfiles that failtsc -bwith TS6133 when every field of an entity renders without the generic formatter. The main case is a join entity whose fields are all to-one relations to targets that have@display. The detail template always importsformatFieldValueand always declaresisEmpty, but only the composite branch and the generic fallback branch use them. The relation-link and file branches use neither. The list template has the same problem with itsformatFieldValueimport: relations default to@list(hidden), so an all-relation entity with no@listhints gets a list page with only the ID column and an unused import. The scaffold'stsconfig.jsonsetsnoUnusedLocals, sopnpm buildfails as generated.This is the same class of problem as #43 (which gated the
Linkimport and theformparameter), for symbols that are still emitted unconditionally.Version checked
v0.45.0 release binary (x86_64 Linux, PostgreSQL build), source at tag
v0.45.0(10ec403).Reproduction
Actual:
With
@list(primary)onproduct, the list page compiles (the primary cell callsformatFieldValue), but the detail page still fails. Both files are Owned (rewritten on every run), so they cannot be fixed in place. The only workaround is a--templates-diroverride of the template.Expected
The scaffold builds for any valid schema set, including join entities that hold only relations, and entities that hold only
filefields.Source
crates/schema-forge-cli/templates/site/src/app/pages/detail.generated.tsx.jinja:19importsformatFieldValueunconditionally.:25-30declaresisEmptyunconditionally.:64(composite sub-fields) and:151-154(the genericelsebranch). Thefilebranch (:82-101) and therelation_one/relation_manybranches with a display field (:102-145) use neither.crates/schema-forge-cli/templates/site/src/app/pages/list.generated.tsx.jinja:11importsformatFieldValueunconditionally. It is used only for a non-enumprimarycell (:90) and the genericcolumncell (:145).context.rs:399-404defaults every relation, file, composite, array, JSON and rich-text field tohidden.crates/schema-forge-cli/src/commands/site/context.rs:145-163:has_relation_linkandhas_file_fieldalready gate theLinkandAttachmentDownloadimports for the samenoUnusedLocalsreason. There is no equivalent flag for these two.crates/schema-forge-cli/src/commands/site/vendor.rs:654: the scaffoldedtsconfig.jsonsets"noUnusedLocals": true.crates/schema-forge-cli/tests/site_generate.rs:495-520: the site-generate: unused imports in .generated.tsx files break TS strict builds #43 regression test covers a relation-free entity only.Suggested fix
Add three flags to
EntityView, next tohas_relation_link:uses_formatter: any field iscomposite, or reaches theelsebranch (anything exceptfile, and except a relation withrelation_display_field).uses_is_empty: any field reaches theelsebranch.list_uses_formatter: any field reaches the list's non-enumprimarycell or its genericcolumncell.Then gate the imports and the helper on them in both templates. Add a
site_generate.rstest that runs the generator on an all-relation entity (with and without@listhints) and on an all-file entity, and asserts that the output passestsc --noEmitor at least contains none of the unused symbols.