@canonical/summon-application 0.29.0-experimental.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/LICENSE +166 -0
  2. package/README.md +75 -13
  3. package/dist/esm/application/react/index.js +347 -0
  4. package/dist/esm/application/react/index.js.map +1 -0
  5. package/dist/esm/application/react/templates/.browserslistrc +2 -0
  6. package/dist/esm/application/react/templates/.storybook/main.ts.ejs +10 -0
  7. package/{src → dist/esm}/application/react/templates/README.md.ejs +54 -0
  8. package/dist/esm/application/react/templates/biome.json.ejs +6 -0
  9. package/dist/esm/application/react/templates/gitignore +25 -0
  10. package/{src → dist/esm}/application/react/templates/package.json.ejs +36 -2
  11. package/dist/esm/application/react/templates/patches/react-relay@18.2.0.patch +52 -0
  12. package/dist/esm/application/react/templates/patches/relay-runtime-network@0.1.0.patch +46 -0
  13. package/dist/esm/application/react/templates/relay.config.json +8 -0
  14. package/{src/application/react/templates/src/client/entry.tsx → dist/esm/application/react/templates/src/client/entry.tsx.ejs} +23 -0
  15. package/dist/esm/application/react/templates/src/domains/catalog/CatalogPage.tsx +50 -0
  16. package/dist/esm/application/react/templates/src/domains/catalog/ErrorBoundary.tests.tsx +56 -0
  17. package/dist/esm/application/react/templates/src/domains/catalog/ErrorBoundary.tsx +37 -0
  18. package/dist/esm/application/react/templates/src/domains/catalog/ProductCard.tsx +49 -0
  19. package/dist/esm/application/react/templates/src/domains/catalog/ProductList.stories.tsx +103 -0
  20. package/dist/esm/application/react/templates/src/domains/catalog/ProductList.tests.tsx +80 -0
  21. package/dist/esm/application/react/templates/src/domains/catalog/ProductList.tsx +59 -0
  22. package/dist/esm/application/react/templates/src/domains/catalog/routes.ts +11 -0
  23. package/dist/esm/application/react/templates/src/lib/ClientOnly/ClientOnly.tests.tsx +35 -0
  24. package/dist/esm/application/react/templates/src/lib/ClientOnly/ClientOnly.tsx +31 -0
  25. package/dist/esm/application/react/templates/src/lib/ClientOnly/index.ts +1 -0
  26. package/{src → dist/esm}/application/react/templates/src/lib/Navigation/Navigation.tsx.ejs +3 -0
  27. package/{src/application/react/templates/src/lib/index.ts → dist/esm/application/react/templates/src/lib/index.ts.ejs} +3 -0
  28. package/dist/esm/application/react/templates/src/relay/__generated__/ProductCard_product.graphql.ts +82 -0
  29. package/dist/esm/application/react/templates/src/relay/__generated__/ProductListQuery.graphql.ts +272 -0
  30. package/dist/esm/application/react/templates/src/relay/environment.tests.ts +87 -0
  31. package/dist/esm/application/react/templates/src/relay/environment.ts +119 -0
  32. package/dist/esm/application/react/templates/src/relay/schema.graphql +111 -0
  33. package/dist/esm/application/react/templates/src/relay/schema.tests.ts +137 -0
  34. package/dist/esm/application/react/templates/src/relay/schema.ts +205 -0
  35. package/{src → dist/esm}/application/react/templates/src/routes.tsx.ejs +10 -0
  36. package/{src/application/react/templates/src/server/entry.tsx → dist/esm/application/react/templates/src/server/entry.tsx.ejs} +36 -0
  37. package/{src → dist/esm}/application/react/templates/src/sitemap/getSitemapItems.ts.ejs +3 -0
  38. package/{src/application/react/templates/tsconfig.json → dist/esm/application/react/templates/tsconfig.json.ejs} +3 -0
  39. package/dist/esm/application/react/templates/vite.config.ts.ejs +92 -0
  40. package/dist/esm/application/react/templates/vitest.setup.ts.ejs +22 -0
  41. package/dist/esm/domain/index.js +89 -0
  42. package/dist/esm/domain/index.js.map +1 -0
  43. package/{src/index.ts → dist/esm/index.js} +6 -8
  44. package/dist/esm/index.js.map +1 -0
  45. package/dist/esm/route/index.js +115 -0
  46. package/dist/esm/route/index.js.map +1 -0
  47. package/dist/esm/route/insertRoute.js +178 -0
  48. package/dist/esm/route/insertRoute.js.map +1 -0
  49. package/dist/esm/shared/casing.js +15 -0
  50. package/dist/esm/shared/casing.js.map +1 -0
  51. package/dist/esm/shared/packageManager.js +38 -0
  52. package/dist/esm/shared/packageManager.js.map +1 -0
  53. package/dist/esm/shared/versions.js +88 -0
  54. package/dist/esm/shared/versions.js.map +1 -0
  55. package/dist/esm/wrapper/index.js +72 -0
  56. package/dist/esm/wrapper/index.js.map +1 -0
  57. package/dist/types/application/react/index.d.ts +12 -0
  58. package/dist/types/application/react/index.d.ts.map +1 -0
  59. package/dist/types/domain/index.d.ts +7 -0
  60. package/dist/types/domain/index.d.ts.map +1 -0
  61. package/dist/types/index.d.ts +8 -0
  62. package/dist/types/index.d.ts.map +1 -0
  63. package/dist/types/route/index.d.ts +7 -0
  64. package/dist/types/route/index.d.ts.map +1 -0
  65. package/dist/types/route/insertRoute.d.ts +34 -0
  66. package/dist/types/route/insertRoute.d.ts.map +1 -0
  67. package/{src/shared/casing.ts → dist/types/shared/casing.d.ts} +2 -7
  68. package/dist/types/shared/casing.d.ts.map +1 -0
  69. package/dist/types/shared/packageManager.d.ts +19 -0
  70. package/dist/types/shared/packageManager.d.ts.map +1 -0
  71. package/dist/types/shared/versions.d.ts +15 -0
  72. package/dist/types/shared/versions.d.ts.map +1 -0
  73. package/dist/types/wrapper/index.d.ts +7 -0
  74. package/dist/types/wrapper/index.d.ts.map +1 -0
  75. package/package.json +17 -15
  76. package/src/application/react/index.ts +0 -294
  77. package/src/application/react/templates/.storybook/main.ts +0 -5
  78. package/src/application/react/templates/biome.json.ejs +0 -6
  79. package/src/application/react/templates/vite.config.ts +0 -45
  80. package/src/application/react/templates/vitest.setup.ts +0 -9
  81. package/src/domain/index.ts +0 -119
  82. package/src/index.test.ts +0 -398
  83. package/src/route/index.ts +0 -154
  84. package/src/route/insertRoute.test.ts +0 -98
  85. package/src/route/insertRoute.ts +0 -236
  86. package/src/shared/versions.ts +0 -48
  87. package/src/wrapper/index.ts +0 -100
  88. /package/{src → dist/esm}/application/react/templates/.storybook/decorators/index.ts +0 -0
  89. /package/{src → dist/esm}/application/react/templates/.storybook/decorators/withRouter.tsx +0 -0
  90. /package/{src → dist/esm}/application/react/templates/.storybook/preview.ts +0 -0
  91. /package/{src → dist/esm}/application/react/templates/index.html.ejs +0 -0
  92. /package/{src → dist/esm}/application/react/templates/public/.gitkeep +0 -0
  93. /package/{src → dist/esm}/application/react/templates/public/robots.txt +0 -0
  94. /package/{src → dist/esm}/application/react/templates/src/assets/.gitkeep +0 -0
  95. /package/{src → dist/esm}/application/react/templates/src/domains/account/AccountPage.tsx +0 -0
  96. /package/{src → dist/esm}/application/react/templates/src/domains/account/LoginPage.tsx +0 -0
  97. /package/{src → dist/esm}/application/react/templates/src/domains/account/routes.ts +0 -0
  98. /package/{src → dist/esm}/application/react/templates/src/domains/contact/ContactPage.tsx +0 -0
  99. /package/{src → dist/esm}/application/react/templates/src/domains/contact/routes.ts +0 -0
  100. /package/{src → dist/esm}/application/react/templates/src/domains/marketing/GuidePage.tsx +0 -0
  101. /package/{src → dist/esm}/application/react/templates/src/domains/marketing/HomePage.tsx +0 -0
  102. /package/{src → dist/esm}/application/react/templates/src/domains/marketing/routes.ts +0 -0
  103. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/ExampleComponent.stories.tsx +0 -0
  104. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/ExampleComponent.tests.tsx +0 -0
  105. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/ExampleComponent.tsx +0 -0
  106. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/index.ts +0 -0
  107. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/styles.css +0 -0
  108. /package/{src → dist/esm}/application/react/templates/src/lib/ExampleComponent/types.ts +0 -0
  109. /package/{src → dist/esm}/application/react/templates/src/lib/LazyComponent/LazyComponent.stories.tsx +0 -0
  110. /package/{src → dist/esm}/application/react/templates/src/lib/LazyComponent/LazyComponent.tsx +0 -0
  111. /package/{src → dist/esm}/application/react/templates/src/lib/LazyComponent/index.ts +0 -0
  112. /package/{src → dist/esm}/application/react/templates/src/lib/Navigation/index.ts +0 -0
  113. /package/{src → dist/esm}/application/react/templates/src/lib/ThemeSelector/ThemeSelector.tsx +0 -0
  114. /package/{src → dist/esm}/application/react/templates/src/lib/ThemeSelector/index.ts +0 -0
  115. /package/{src → dist/esm}/application/react/templates/src/server/preview.bun.ts +0 -0
  116. /package/{src → dist/esm}/application/react/templates/src/server/preview.express.ts +0 -0
  117. /package/{src → dist/esm}/application/react/templates/src/server/renderer.tsx +0 -0
  118. /package/{src → dist/esm}/application/react/templates/src/server/server.bun.ts +0 -0
  119. /package/{src → dist/esm}/application/react/templates/src/server/server.express.ts +0 -0
  120. /package/{src → dist/esm}/application/react/templates/src/sitemap/renderer.ts +0 -0
  121. /package/{src → dist/esm}/application/react/templates/src/styles/app.css +0 -0
  122. /package/{src → dist/esm}/application/react/templates/src/styles/index.css.ejs +0 -0
  123. /package/{src → dist/esm}/application/react/templates/src/vite-env.d.ts +0 -0
  124. /package/{src → dist/esm}/application/react/templates/test/e2e/serverHarness.ts +0 -0
  125. /package/{src → dist/esm}/application/react/templates/test/e2e/servers.e2e.ts +0 -0
  126. /package/{src → dist/esm}/application/react/templates/vitest.config.ts +0 -0
  127. /package/{src → dist/esm}/application/react/templates/vitest.e2e.config.ts +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/application/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAKzC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EACL,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,IAAI,GACL,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAWhE,MAAM,OAAO,GAAuB;IAClC;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,MAAM;QAC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F,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ # The app's browser floor — Lightning CSS downlevels all CSS to this query (see vite.config.ts); edit it to widen or narrow support.
2
+ defaults
@@ -0,0 +1,10 @@
1
+ import { createConfig } from "@canonical/storybook-config";
2
+
3
+ export default createConfig("react", {
4
+ staticDirs: ["../src/assets", "../public"],
5
+ <% if (relay) { -%>
6
+ // Wraps stories that declare `parameters.relay` in a relay-test-utils mock
7
+ // environment, so components using Relay hooks render without a server.
8
+ extraAddons: ["@canonical/storybook-addon-relay"],
9
+ <% } -%>
10
+ });
@@ -36,6 +36,15 @@ renderer over the built assets, the same artifact that deploys.
36
36
  ```bash
37
37
  bun run storybook # component workshop
38
38
  ```
39
+ <% if (relay) { -%>
40
+
41
+ Relay's compiler artifacts are committed, not rebuilt on the fly:
42
+
43
+ ```bash
44
+ bun run relay # regenerate src/relay/__generated__ after schema/query edits
45
+ bun run relay:watch # the same, re-running on change — pair with dev:*
46
+ ```
47
+ <% } -%>
39
48
 
40
49
  ## Adding routes
41
50
 
@@ -69,6 +78,10 @@ src/
69
78
  ├── server/ Server entry, compiled renderer, dev servers, sitemap
70
79
  ├── domains/ Feature domains (each owns its routes and pages)
71
80
  ├── lib/ Shared components
81
+ <% if (relay) { -%>
82
+ ├── relay/ Relay environment factory, executable mock schema,
83
+ │ and generated artifacts (__generated__/)
84
+ <% } -%>
72
85
  ├── styles/ Application CSS
73
86
  ├── assets/ Assets imported in code (bundled and hashed by Vite)
74
87
  └── routes.tsx Root route map
@@ -80,3 +93,44 @@ Domains are the unit of feature organisation: each owns its routes and pages, so
80
93
  adding a feature is adding a domain rather than threading changes through shared
81
94
  files. This app ships both `src/assets/` (assets imported in code) and `public/`
82
95
  (files served by fixed URL); either may be removed if the app uses only one.
96
+ <% if (relay) { -%>
97
+
98
+ ## Data layer (Relay)
99
+
100
+ The `catalog` domain demonstrates the app's [Relay](https://relay.dev) data
101
+ layer: `ProductList` fetches a page of products with `useLazyLoadQuery`, and
102
+ each `ProductCard` reads its own colocated `useFragment` — the component owns
103
+ its field selection, the parent query just spreads it.
104
+
105
+ **By default the app needs no backend.** `createEnvironment`
106
+ (`src/relay/environment.ts`) resolves every GraphQL operation in-process
107
+ against an executable mock schema (`src/relay/schema.ts`, built from the SDL
108
+ in `src/relay/schema.graphql`) backed by a small deterministic catalog. Set
109
+ `VITE_GRAPHQL_URL` (or pass `graphqlUrl` to `createEnvironment`) to switch the
110
+ environment to posting operations to a real GraphQL endpoint instead — no code
111
+ changes needed.
112
+
113
+ **Generated artifacts are committed.** The Vite plugin runs with
114
+ `codegen: false`, so `src/relay/__generated__/` is not rebuilt on the fly:
115
+ after editing a `graphql` tag or the schema, run `bun run relay` (or keep
116
+ `bun run relay:watch` running) to regenerate the artifacts, and commit them.
117
+
118
+ **SSR ships no data yet.** `useLazyLoadQuery` fetches (and suspends) while
119
+ rendering, and the server cannot serialize the fetched store for the client
120
+ yet, so the catalog page wraps its query subtree in `ClientOnly`
121
+ (`src/lib/ClientOnly/`): the server streams the fallback and the browser
122
+ fetches after hydration.
123
+
124
+ **Patched dependencies.** `patches/` carries two package patches applied via
125
+ `patchedDependencies` in `package.json` (a bun feature — with another package
126
+ manager, apply the equivalent mechanism): `react-relay@18.2.0` needs a
127
+ cjs-module-lexer export hint so named imports survive Node SSR, and
128
+ `relay-runtime-network@0.1.0` ships a broken `imports` map. The latter patch
129
+ is temporary until the fixed upstream release lands
130
+ ([advl/lit-relay#32](https://github.com/advl/lit-relay/pull/32)); drop it and
131
+ its `patchedDependencies` entry once a fixed version is published.
132
+
133
+ **Not yet on npm.** `@canonical/storybook-addon-relay` and the fixed
134
+ `relay-runtime-network` release have not been published yet, so a fresh
135
+ install of this app will not fully resolve until they land on npm.
136
+ <% } -%>
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": ["@canonical/biome-config"],
3
+ "files": {
4
+ "includes": ["src", "*.json", "vite.config.ts"<% if (relay) { %>, "!src/relay/__generated__"<% } %>]
5
+ }
6
+ }
@@ -0,0 +1,25 @@
1
+ # Logs
2
+ logs
3
+ *.log
4
+ npm-debug.log*
5
+ yarn-debug.log*
6
+ yarn-error.log*
7
+ pnpm-debug.log*
8
+ lerna-debug.log*
9
+
10
+ node_modules
11
+ dist
12
+ dist-ssr
13
+ *.local
14
+ *.tsbuildinfo
15
+
16
+ # Editor directories and files
17
+ .vscode/*
18
+ !.vscode/extensions.json
19
+ .idea
20
+ .DS_Store
21
+ *.suo
22
+ *.ntvs*
23
+ *.njsproj
24
+ *.sln
25
+ *.sw?
@@ -7,6 +7,9 @@
7
7
  "imports": {
8
8
  "#lib/*": "./src/lib/*",
9
9
  "#domains/*": "./src/domains/*",
10
+ <% if (relay) { -%>
11
+ "#relay/*": "./src/relay/*",
12
+ <% } -%>
10
13
  "#styles/*": "./src/styles/*"
11
14
  },
12
15
  "scripts": {
@@ -26,6 +29,10 @@
26
29
  "check:biome": "biome check",
27
30
  "check:biome:fix": "biome check --write",
28
31
  "check:ts": "tsc --noEmit",
32
+ <% if (relay) { -%>
33
+ "relay": "relay-compiler",
34
+ "relay:watch": "relay-compiler --watch",
35
+ <% } -%>
29
36
  "test": "vitest run",
30
37
  "test:watch": "vitest",
31
38
  "test:coverage": "vitest run --coverage",
@@ -42,11 +49,20 @@
42
49
  "@canonical/react-ssr": "<%= pragmaVersion %>",
43
50
  "@canonical/router-core": "<%= pragmaVersion %>",
44
51
  "@canonical/router-react": "<%= pragmaVersion %>",
52
+ <% if (relay) { -%>
53
+ "@canonical/storybook-addon-relay": "<%= pragmaVersion %>",
54
+ <% } -%>
45
55
  "@canonical/storybook-config": "<%= pragmaVersion %>",
46
56
  "@canonical/styles": "<%= pragmaVersion %>",
47
57
  "express": "^5.2.1",
58
+ <% if (relay) { -%>
59
+ "graphql": "^16.11.0",
60
+ <% } -%>
48
61
  "react": "^19.2.4",
49
- "react-dom": "^19.2.4"
62
+ "react-dom": "^19.2.4"<% if (relay) { %>,
63
+ "react-relay": "^18.2.0",
64
+ "relay-runtime": "^18.2.0",
65
+ "relay-runtime-network": "^0.1.0"<% } %>
50
66
  },
51
67
  "devDependencies": {
52
68
  "@biomejs/biome": "2.4.9",
@@ -59,14 +75,32 @@
59
75
  "@types/node": "^24.12.0",
60
76
  "@types/react": "^19.2.14",
61
77
  "@types/react-dom": "^19.2.3",
78
+ <% if (relay) { -%>
79
+ "@types/react-relay": "^18.2.1",
80
+ "@types/relay-runtime": "^19.0.3",
81
+ "@types/relay-test-utils": "^18.0.0",
82
+ <% } -%>
62
83
  "@vitejs/plugin-react": "^6.0.0",
63
84
  "@vitest/coverage-v8": "^4.0.18",
85
+ "browserslist": "^4.28.1",
64
86
  "bun-types": "^1.3.9",
65
87
  "jsdom": "^28.1.0",
88
+ "lightningcss": "^1.32.0",
89
+ <% if (relay) { -%>
90
+ "relay-compiler": "^18.2.0",
91
+ "relay-test-utils": "^18.2.0",
92
+ <% } -%>
66
93
  "storybook": "^10.3.1",
67
94
  "tsx": "^4.19.0",
68
95
  "typescript": "^5.9.3",
69
96
  "vite": "^8.0.1",
97
+ <% if (relay) { -%>
98
+ "vite-plugin-relay-lite": "^0.12.0",
99
+ <% } -%>
70
100
  "vitest": "^4.0.18"
71
- }
101
+ }<% if (relay) { %>,
102
+ "patchedDependencies": {
103
+ "react-relay@18.2.0": "patches/react-relay@18.2.0.patch",
104
+ "relay-runtime-network@0.1.0": "patches/relay-runtime-network@0.1.0.patch"
105
+ }<% } %>
72
106
  }
@@ -0,0 +1,52 @@
1
+ diff --git a/index.js b/index.js
2
+ index 5fe5bc4a2adf6210e2dc5f84cc33382f47953384..407b9665ffa3b703f8fb2bfffa843a869b5c0957 100644
3
+ --- a/index.js
4
+ +++ b/index.js
5
+ @@ -8,3 +8,47 @@
6
+ */
7
+
8
+ module.exports = require('./lib/index.js');
9
+ +
10
+ +// Patch (pragma): cjs-module-lexer cannot statically detect the exports of
11
+ +// ./lib/index.js because they are member expressions inside an object
12
+ +// literal, so `import { useFragment } from "react-relay"` fails under Node
13
+ +// ESM (and under Vite's dev SSR module runner, which mirrors Node semantics).
14
+ +// The dead branch below is the esbuild-style lexer hint: never executed, but
15
+ +// statically registers the named exports.
16
+ +0 && (module.exports = {
17
+ + ConnectionHandler: null,
18
+ + QueryRenderer: null,
19
+ + LocalQueryRenderer: null,
20
+ + MutationTypes: null,
21
+ + RangeOperations: null,
22
+ + ReactRelayContext: null,
23
+ + applyOptimisticMutation: null,
24
+ + commitLocalUpdate: null,
25
+ + commitMutation: null,
26
+ + createFragmentContainer: null,
27
+ + createPaginationContainer: null,
28
+ + createRefetchContainer: null,
29
+ + fetchQuery_DEPRECATED: null,
30
+ + graphql: null,
31
+ + readInlineData: null,
32
+ + requestSubscription: null,
33
+ + EntryPointContainer: null,
34
+ + RelayEnvironmentProvider: null,
35
+ + ProfilerContext: null,
36
+ + fetchQuery: null,
37
+ + loadQuery: null,
38
+ + loadEntryPoint: null,
39
+ + useClientQuery: null,
40
+ + useFragment: null,
41
+ + useLazyLoadQuery: null,
42
+ + useEntryPointLoader: null,
43
+ + useQueryLoader: null,
44
+ + useMutation: null,
45
+ + usePaginationFragment: null,
46
+ + usePreloadedQuery: null,
47
+ + useRefetchableFragment: null,
48
+ + usePrefetchableForwardPaginationFragment_EXPERIMENTAL: null,
49
+ + useRelayEnvironment: null,
50
+ + useSubscribeToInvalidationState: null,
51
+ + useSubscription: null,
52
+ +});
@@ -0,0 +1,46 @@
1
+ diff --git a/package.json b/package.json
2
+ index e07d3e3d0a22b44df7eb9e0234b3d4e834ed02f2..361aaa655faf54fa13252696ffb248cc4f2694f7 100644
3
+ --- a/package.json
4
+ +++ b/package.json
5
+ @@ -24,13 +24,34 @@
6
+ "test:watch": "vitest"
7
+ },
8
+ "imports": {
9
+ - "#auth/*": "./src/lib/auth/*",
10
+ - "#errors/*": "./src/lib/errors/*",
11
+ - "#executors/*": "./src/lib/executors/*",
12
+ - "#middlewares/*": "./src/lib/middlewares/*",
13
+ - "#ssr/*": "./src/lib/ssr/*",
14
+ - "#testing/*": "./src/lib/testing/*",
15
+ - "#types/*": "./src/lib/types/*"
16
+ + "#auth/*": {
17
+ + "types": "./dist/types/lib/auth/*",
18
+ + "default": "./dist/esm/lib/auth/*"
19
+ + },
20
+ + "#errors/*": {
21
+ + "types": "./dist/types/lib/errors/*",
22
+ + "default": "./dist/esm/lib/errors/*"
23
+ + },
24
+ + "#executors/*": {
25
+ + "types": "./dist/types/lib/executors/*",
26
+ + "default": "./dist/esm/lib/executors/*"
27
+ + },
28
+ + "#middlewares/*": {
29
+ + "types": "./dist/types/lib/middlewares/*",
30
+ + "default": "./dist/esm/lib/middlewares/*"
31
+ + },
32
+ + "#ssr/*": {
33
+ + "types": "./dist/types/lib/ssr/*",
34
+ + "default": "./dist/esm/lib/ssr/*"
35
+ + },
36
+ + "#testing/*": {
37
+ + "types": "./dist/types/lib/testing/*",
38
+ + "default": "./dist/esm/lib/testing/*"
39
+ + },
40
+ + "#types/*": {
41
+ + "types": "./dist/types/lib/types/*",
42
+ + "default": "./dist/esm/lib/types/*"
43
+ + }
44
+ },
45
+ "peerDependencies": {
46
+ "relay-runtime": ">=16.0.0"
@@ -0,0 +1,8 @@
1
+ {
2
+ "src": "./src",
3
+ "schema": "./src/relay/schema.graphql",
4
+ "language": "typescript",
5
+ "eagerEsModules": true,
6
+ "artifactDirectory": "./src/relay/__generated__",
7
+ "excludes": ["**/node_modules/**", "**/__generated__/**", "**/dist/**"]
8
+ }
@@ -2,6 +2,10 @@ import { HeadProvider } from "@canonical/react-head";
2
2
  import { createBrowserRouter } from "@canonical/router-core";
3
3
  import { Outlet, RouterProvider } from "@canonical/router-react";
4
4
  import { hydrateRoot } from "react-dom/client";
5
+ <% if (relay) { -%>
6
+ import { RelayEnvironmentProvider } from "react-relay";
7
+ import { createEnvironment } from "#relay/environment.js";
8
+ <% } -%>
5
9
  import { appRoutes, middleware, notFoundRoute } from "../routes.js";
6
10
  import "#styles/index.css";
7
11
 
@@ -9,12 +13,30 @@ const router = createBrowserRouter(appRoutes, {
9
13
  middleware: [...middleware],
10
14
  notFound: notFoundRoute,
11
15
  });
16
+ <% if (relay) { -%>
17
+
18
+ // One Relay environment (network + normalized store) for the whole browser
19
+ // session — module scope, so client-side navigations share the cache.
20
+ const relayEnvironment = createEnvironment();
21
+ <% } -%>
12
22
 
13
23
  const root = document.getElementById("root");
14
24
  if (!root) {
15
25
  throw new Error('Root element "#root" not found');
16
26
  }
17
27
 
28
+ <% if (relay) { -%>
29
+ hydrateRoot(
30
+ root,
31
+ <HeadProvider>
32
+ <RelayEnvironmentProvider environment={relayEnvironment}>
33
+ <RouterProvider router={router}>
34
+ <Outlet fallback={<p>Loading…</p>} />
35
+ </RouterProvider>
36
+ </RelayEnvironmentProvider>
37
+ </HeadProvider>,
38
+ );
39
+ <% } else { -%>
18
40
  hydrateRoot(
19
41
  root,
20
42
  <HeadProvider>
@@ -23,3 +45,4 @@ hydrateRoot(
23
45
  </RouterProvider>
24
46
  </HeadProvider>,
25
47
  );
48
+ <% } -%>
@@ -0,0 +1,50 @@
1
+ import { useHead } from "@canonical/react-head";
2
+ import { type ReactElement, Suspense } from "react";
3
+ import { ClientOnly } from "#lib/index.js";
4
+ import ErrorBoundary from "./ErrorBoundary.js";
5
+ import ProductList from "./ProductList.js";
6
+
7
+ export default function CatalogPage(): ReactElement {
8
+ useHead({ title: "Catalog — Boilerplate" });
9
+
10
+ return (
11
+ <section aria-labelledby="catalog-title">
12
+ <h1 id="catalog-title">Catalog</h1>
13
+ <p>
14
+ This page demonstrates the Relay data layer. <code>ProductList</code>{" "}
15
+ issues a <code>useLazyLoadQuery</code>, each <code>ProductCard</code>{" "}
16
+ reads its own <code>useFragment</code>, and the environment resolves
17
+ operations against the local mock schema in{" "}
18
+ <code>src/relay/schema.ts</code> — set <code>VITE_GRAPHQL_URL</code> to
19
+ point it at a real endpoint instead.
20
+ </p>
21
+ {/*
22
+ SSR guard: `useLazyLoadQuery` fetches (and suspends) while rendering,
23
+ and the server has no way to serialize the fetched store for the
24
+ client yet — that lands in the follow-up SSR data-hydration PR. Until
25
+ then `ClientOnly` keeps the query off the server render path: the
26
+ server streams the fallback and the browser fetches after hydration.
27
+ */}
28
+ {/*
29
+ The canonical Relay pairing: Suspense renders the pending state while
30
+ `useLazyLoadQuery` is in flight, and the ErrorBoundary renders the
31
+ failure state when the query errors (e.g. an unreachable endpoint in
32
+ `VITE_GRAPHQL_URL` mode) — without it a thrown query error would
33
+ unmount the whole tree to a blank page.
34
+ */}
35
+ <ClientOnly fallback={<p>Loading catalog…</p>}>
36
+ <ErrorBoundary
37
+ fallback={
38
+ <p role="alert">
39
+ The catalog failed to load. Reload the page to try again.
40
+ </p>
41
+ }
42
+ >
43
+ <Suspense fallback={<p>Loading catalog…</p>}>
44
+ <ProductList />
45
+ </Suspense>
46
+ </ErrorBoundary>
47
+ </ClientOnly>
48
+ </section>
49
+ );
50
+ }
@@ -0,0 +1,56 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import { Suspense } from "react";
3
+ import { RelayEnvironmentProvider } from "react-relay";
4
+ import { createMockEnvironment } from "relay-test-utils";
5
+ import { afterEach, describe, expect, it, vi } from "vitest";
6
+ import ErrorBoundary from "./ErrorBoundary.js";
7
+ import ProductList from "./ProductList.js";
8
+
9
+ describe("ErrorBoundary component", () => {
10
+ afterEach(() => {
11
+ vi.restoreAllMocks();
12
+ });
13
+
14
+ it("renders its children while nothing throws", () => {
15
+ render(
16
+ <ErrorBoundary fallback={<p role="alert">Failed.</p>}>
17
+ <p>Catalog content</p>
18
+ </ErrorBoundary>,
19
+ );
20
+
21
+ expect(screen.getByText("Catalog content")).toBeInTheDocument();
22
+ expect(screen.queryByRole("alert")).not.toBeInTheDocument();
23
+ });
24
+
25
+ it("renders the fallback when the catalog query errors", async () => {
26
+ // React logs errors caught by boundaries; keep the test output clean.
27
+ vi.spyOn(console, "error").mockImplementation(() => {});
28
+
29
+ const environment = createMockEnvironment();
30
+ // Resolving an operation with an Error rejects it, which makes
31
+ // `useLazyLoadQuery` re-throw during render — exactly what happens when
32
+ // a real endpoint is unreachable. Queue it before rendering, as the
33
+ // query is issued during the initial render.
34
+ environment.mock.queueOperationResolver(
35
+ () => new Error("backend unreachable"),
36
+ );
37
+
38
+ render(
39
+ <RelayEnvironmentProvider environment={environment}>
40
+ <ErrorBoundary
41
+ fallback={<p role="alert">The catalog failed to load.</p>}
42
+ >
43
+ <Suspense fallback={<p>Loading catalog…</p>}>
44
+ <ProductList />
45
+ </Suspense>
46
+ </ErrorBoundary>
47
+ </RelayEnvironmentProvider>,
48
+ );
49
+
50
+ // The fallback replaces the subtree instead of white-screening.
51
+ expect(await screen.findByRole("alert")).toHaveTextContent(
52
+ "The catalog failed to load.",
53
+ );
54
+ expect(screen.queryByText(/products/)).not.toBeInTheDocument();
55
+ });
56
+ });
@@ -0,0 +1,37 @@
1
+ import { Component, type ReactNode } from "react";
2
+
3
+ export interface ErrorBoundaryProps {
4
+ /** Subtree whose render errors this boundary catches. */
5
+ readonly children: ReactNode;
6
+ /** Rendered in place of `children` after an error. */
7
+ readonly fallback: ReactNode;
8
+ }
9
+
10
+ interface ErrorBoundaryState {
11
+ readonly hasError: boolean;
12
+ }
13
+
14
+ /**
15
+ * Catches render errors below it and renders `fallback` instead of letting
16
+ * the error unmount the whole tree to a blank page.
17
+ *
18
+ * Relay's `useLazyLoadQuery` re-throws query errors during render — Suspense
19
+ * only handles the pending state — so a data-driven subtree needs both
20
+ * boundaries: Suspense for loading, this for failure (the canonical Relay
21
+ * pairing; see `CatalogPage`). A class component because error boundaries
22
+ * have no hook equivalent.
23
+ */
24
+ export default class ErrorBoundary extends Component<
25
+ ErrorBoundaryProps,
26
+ ErrorBoundaryState
27
+ > {
28
+ state: ErrorBoundaryState = { hasError: false };
29
+
30
+ static getDerivedStateFromError(): ErrorBoundaryState {
31
+ return { hasError: true };
32
+ }
33
+
34
+ render(): ReactNode {
35
+ return this.state.hasError ? this.props.fallback : this.props.children;
36
+ }
37
+ }
@@ -0,0 +1,49 @@
1
+ import type { ReactElement } from "react";
2
+ import { graphql, useFragment } from "react-relay";
3
+ import type { ProductCard_product$key } from "#relay/__generated__/ProductCard_product.graphql.js";
4
+
5
+ // Data this card needs, colocated with the component. The parent query
6
+ // spreads the fragment, so the card can evolve its field selection without
7
+ // touching `ProductList`.
8
+ const productCardFragment = graphql`
9
+ fragment ProductCard_product on Product {
10
+ name
11
+ tagline
12
+ priceCents
13
+ currency
14
+ rating
15
+ inStock
16
+ }
17
+ `;
18
+
19
+ /** Formats a minor-unit price deterministically (fixed locale, real currency). */
20
+ const formatPrice = (priceCents: number, currency: string): string =>
21
+ new Intl.NumberFormat("en-US", { style: "currency", currency }).format(
22
+ priceCents / 100,
23
+ );
24
+
25
+ export interface ProductCardProps {
26
+ /** Fragment reference to the product this card renders. */
27
+ readonly product: ProductCard_product$key;
28
+ }
29
+
30
+ /**
31
+ * Renders one catalog product from a Relay fragment reference.
32
+ */
33
+ export default function ProductCard({
34
+ product,
35
+ }: ProductCardProps): ReactElement {
36
+ const data = useFragment(productCardFragment, product);
37
+
38
+ return (
39
+ <article aria-label={data.name}>
40
+ <h3>{data.name}</h3>
41
+ <p>{data.tagline}</p>
42
+ <p>
43
+ <strong>{formatPrice(data.priceCents, data.currency)}</strong> · rated{" "}
44
+ {data.rating.toFixed(1)} / 5 ·{" "}
45
+ {data.inStock ? "in stock" : "out of stock"}
46
+ </p>
47
+ </article>
48
+ );
49
+ }