@quilted/create 0.1.77 → 0.1.79

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 (112) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/cjs/app.cjs +20 -18
  3. package/build/cjs/module.cjs +15 -13
  4. package/build/cjs/package.cjs +10 -9
  5. package/build/cjs/service.cjs +8 -12
  6. package/build/esm/app.mjs +20 -18
  7. package/build/esm/module.mjs +15 -13
  8. package/build/esm/package.mjs +10 -9
  9. package/build/esm/service.mjs +8 -12
  10. package/build/esnext/app.esnext +20 -18
  11. package/build/esnext/module.esnext +15 -13
  12. package/build/esnext/package.esnext +10 -9
  13. package/build/tsconfig.tsbuildinfo +1 -1
  14. package/build/typescript/app.d.ts.map +1 -1
  15. package/build/typescript/module.d.ts.map +1 -1
  16. package/build/typescript/package.d.ts.map +1 -1
  17. package/build/typescript/service.d.ts.map +1 -1
  18. package/build/typescript/shared.d.ts +1 -1
  19. package/build/typescript/shared.d.ts.map +1 -1
  20. package/package.json +1 -1
  21. package/source/app.ts +35 -31
  22. package/source/module.ts +26 -22
  23. package/source/package.ts +20 -23
  24. package/source/service.ts +18 -23
  25. package/source/shared.ts +0 -2
  26. package/templates/app-basic/App.tsx +37 -13
  27. package/templates/app-basic/browser.tsx +2 -2
  28. package/templates/app-basic/features/start/Start/Start.tsx +5 -0
  29. package/templates/app-basic/features/start.ts +5 -0
  30. package/templates/app-basic/foundation/frame/Frame.module.css +14 -0
  31. package/templates/app-basic/foundation/frame/Frame.tsx +7 -0
  32. package/templates/app-basic/foundation/frame.ts +1 -0
  33. package/templates/app-basic/foundation/{Head → html}/Head.test.tsx +4 -4
  34. package/templates/app-basic/foundation/html.ts +1 -0
  35. package/templates/{app-trpc/foundation/Http/Http.test.tsx → app-basic/foundation/http/Headers.test.tsx} +8 -8
  36. package/templates/app-basic/foundation/{Http/Http.tsx → http/Headers.tsx} +3 -3
  37. package/templates/app-basic/foundation/http.ts +1 -0
  38. package/templates/app-basic/server.tsx +18 -15
  39. package/templates/app-basic/shared/context.ts +1 -6
  40. package/templates/app-basic/tests/render/render.tsx +12 -12
  41. package/templates/app-basic/tests/render/types.ts +3 -5
  42. package/templates/app-basic/tests/render.ts +2 -2
  43. package/templates/app-empty/App.tsx +1 -1
  44. package/templates/app-empty/browser.tsx +1 -1
  45. package/templates/app-empty/server.tsx +18 -14
  46. package/templates/app-graphql/App.tsx +36 -26
  47. package/templates/app-graphql/browser.tsx +1 -1
  48. package/templates/app-graphql/features/{Start → start/Start}/Start.test.tsx +3 -7
  49. package/templates/app-graphql/features/start/Start/Start.tsx +14 -0
  50. package/templates/app-graphql/features/start.ts +5 -0
  51. package/templates/app-graphql/foundation/frame/Frame.module.css +14 -0
  52. package/templates/app-graphql/foundation/frame/Frame.tsx +7 -0
  53. package/templates/app-graphql/foundation/frame.ts +1 -0
  54. package/templates/{app-trpc/foundation/Head → app-graphql/foundation/html}/Head.test.tsx +4 -4
  55. package/templates/app-graphql/foundation/html.ts +1 -0
  56. package/templates/{app-basic/foundation/Http/Http.test.tsx → app-graphql/foundation/http/Headers.test.tsx} +8 -8
  57. package/templates/app-graphql/foundation/{Http/Http.tsx → http/Headers.tsx} +3 -3
  58. package/templates/app-graphql/foundation/http.ts +1 -0
  59. package/templates/app-graphql/server/graphql.ts +1 -2
  60. package/templates/app-graphql/server.tsx +36 -33
  61. package/templates/app-graphql/shared/context.ts +1 -6
  62. package/templates/app-graphql/tests/graphql.ts +3 -4
  63. package/templates/app-graphql/tests/render/render.tsx +16 -15
  64. package/templates/app-graphql/tests/render/types.ts +3 -5
  65. package/templates/app-graphql/tests/render.ts +3 -3
  66. package/templates/app-trpc/App.tsx +39 -33
  67. package/templates/app-trpc/browser.tsx +1 -1
  68. package/templates/app-trpc/features/{Start → start/Start}/Start.test.tsx +2 -2
  69. package/templates/app-trpc/features/start/Start/Start.tsx +9 -0
  70. package/templates/app-trpc/features/start.ts +5 -0
  71. package/templates/app-trpc/foundation/frame/Frame.module.css +14 -0
  72. package/templates/app-trpc/foundation/frame/Frame.tsx +7 -0
  73. package/templates/app-trpc/foundation/frame.ts +1 -0
  74. package/templates/{app-graphql/foundation/Head → app-trpc/foundation/html}/Head.test.tsx +4 -4
  75. package/templates/app-trpc/foundation/html.ts +1 -0
  76. package/templates/{app-graphql/foundation/Http/Http.test.tsx → app-trpc/foundation/http/Headers.test.tsx} +8 -8
  77. package/templates/app-trpc/foundation/{Http/Http.tsx → http/Headers.tsx} +3 -3
  78. package/templates/app-trpc/foundation/http.ts +1 -0
  79. package/templates/app-trpc/server.tsx +1 -1
  80. package/templates/app-trpc/shared/context.ts +1 -6
  81. package/templates/app-trpc/tests/render/render.tsx +17 -16
  82. package/templates/service-basic/service.ts +2 -2
  83. package/templates/app-basic/features/Start/Start.tsx +0 -12
  84. package/templates/app-basic/features/Start.tsx +0 -3
  85. package/templates/app-basic/foundation/Head.tsx +0 -1
  86. package/templates/app-basic/foundation/Http.tsx +0 -1
  87. package/templates/app-basic/foundation/Metrics/Metrics.tsx +0 -23
  88. package/templates/app-basic/foundation/Metrics.tsx +0 -1
  89. package/templates/app-graphql/features/Start/Start.tsx +0 -20
  90. package/templates/app-graphql/features/Start.tsx +0 -3
  91. package/templates/app-graphql/foundation/Head.tsx +0 -1
  92. package/templates/app-graphql/foundation/Http.tsx +0 -1
  93. package/templates/app-graphql/foundation/Metrics/Metrics.tsx +0 -23
  94. package/templates/app-graphql/foundation/Metrics.tsx +0 -1
  95. package/templates/app-single-file/App.tsx +0 -199
  96. package/templates/app-single-file/package.json +0 -35
  97. package/templates/app-single-file/quilt.project.ts +0 -5
  98. package/templates/app-single-file/tsconfig.json +0 -9
  99. package/templates/app-trpc/features/Start/Start.tsx +0 -16
  100. package/templates/app-trpc/features/Start.tsx +0 -3
  101. package/templates/app-trpc/foundation/Head.tsx +0 -1
  102. package/templates/app-trpc/foundation/Http.tsx +0 -1
  103. package/templates/app-trpc/foundation/Metrics/Metrics.tsx +0 -23
  104. package/templates/app-trpc/foundation/Metrics.tsx +0 -1
  105. /package/templates/app-basic/features/{Start → start/Start}/Start.module.css +0 -0
  106. /package/templates/app-basic/features/{Start → start/Start}/Start.test.tsx +0 -0
  107. /package/templates/app-basic/foundation/{Head → html}/Head.tsx +0 -0
  108. /package/templates/app-graphql/features/{Start → start/Start}/Start.module.css +0 -0
  109. /package/templates/app-graphql/features/{Start → start/Start}/StartQuery.graphql +0 -0
  110. /package/templates/app-graphql/foundation/{Head → html}/Head.tsx +0 -0
  111. /package/templates/app-trpc/features/{Start → start/Start}/Start.module.css +0 -0
  112. /package/templates/app-trpc/foundation/{Head → html}/Head.tsx +0 -0
@@ -1,5 +1,5 @@
1
1
  import Env from '@quilted/quilt/env';
2
- import {useCurrentUrl} from '@quilted/quilt';
2
+ import {useInitialUrl} from '@quilted/quilt/navigate';
3
3
  import {
4
4
  CacheControl,
5
5
  ResponseHeader,
@@ -14,8 +14,8 @@ import {
14
14
  // wherever in your application you can read that state.
15
15
  //
16
16
  // @see https://github.com/lemonmade/quilt/blob/main/documentation/features/http.md
17
- export function Http() {
18
- const isHttps = useCurrentUrl().protocol === 'https:';
17
+ export function Headers() {
18
+ const isHttps = useInitialUrl().protocol === 'https:';
19
19
 
20
20
  return (
21
21
  <>
@@ -0,0 +1 @@
1
+ export {Headers} from './http/Headers.tsx';
@@ -11,7 +11,7 @@ const {createResolver, createQueryResolver} =
11
11
  createGraphQLResolverBuilder<Schema>();
12
12
 
13
13
  const Person = createResolver('Person', {
14
- name: 'Winston',
14
+ name: async () => 'Winston',
15
15
  });
16
16
 
17
17
  const Query = createQueryResolver({
@@ -35,7 +35,6 @@ export async function performGraphQLOperation<
35
35
  source: operation,
36
36
  operationName,
37
37
  variableValues: variables,
38
- rootValue: {name: () => 'Winston'},
39
38
  });
40
39
 
41
40
  return result as GraphQLResult<Data>;
@@ -1,50 +1,53 @@
1
- import '@quilted/quilt/global';
1
+ import '@quilted/quilt/globals';
2
2
 
3
- import {createRequestRouter, json} from '@quilted/quilt/request-router';
4
- import {createServerRender} from '@quilted/quilt/server';
3
+ import {RequestRouter, JSONResponse} from '@quilted/quilt/request-router';
5
4
  import {type GraphQLFetch} from '@quilted/quilt/graphql';
6
- import {createBrowserAssets} from '@quilted/quilt/magic/assets';
5
+ import {BrowserAssets} from '@quilted/quilt/magic/assets';
7
6
 
8
- const router = createRequestRouter();
7
+ const router = new RequestRouter();
8
+ const assets = new BrowserAssets();
9
9
 
10
10
  // GraphQL API, called from the client
11
11
  router.post('/api/graphql', async (request) => {
12
- const [{performGraphQLOperation}, {query, operationName, variables}] =
13
- await Promise.all([import('./server/graphql.ts'), request.json()]);
12
+ const [{query, operationName, variables}, {performGraphQLOperation}] =
13
+ await Promise.all([request.json(), import('./server/graphql.ts')]);
14
14
 
15
15
  const result = await performGraphQLOperation(query, {
16
16
  variables,
17
17
  operationName,
18
18
  });
19
19
 
20
- return json(result);
20
+ return new JSONResponse(result);
21
21
  });
22
22
 
23
23
  // For all GET requests, render our React application.
24
- router.get(
25
- createServerRender(
26
- async () => {
27
- const [{default: App}, {performGraphQLOperation}] = await Promise.all([
28
- import('./App.tsx'),
29
- import('./server/graphql.ts'),
30
- ]);
31
-
32
- // GraphQL API, called during server rendering
33
- const fetchGraphQL: GraphQLFetch = async (operation, variables) => {
34
- const result = await performGraphQLOperation(operation.source, {
35
- variables,
36
- operationName: operation.name,
37
- });
38
-
39
- return result;
40
- };
41
-
42
- return <App fetchGraphQL={fetchGraphQL} />;
43
- },
44
- {
45
- assets: createBrowserAssets(),
46
- },
47
- ),
48
- );
24
+ router.get(async (request) => {
25
+ const [{App}, {performGraphQLOperation}, {renderToResponse}] =
26
+ await Promise.all([
27
+ import('./App.tsx'),
28
+ import('./server/graphql.ts'),
29
+ import('@quilted/quilt/server'),
30
+ ]);
31
+
32
+ // GraphQL API, called during server rendering
33
+ const fetchGraphQL: GraphQLFetch = async (operation, options) => {
34
+ const result = await performGraphQLOperation<any>(
35
+ (operation as any).source,
36
+ {
37
+ variables: options?.variables as any,
38
+ operationName: (operation as any).name,
39
+ },
40
+ );
41
+
42
+ return result;
43
+ };
44
+
45
+ const response = await renderToResponse(<App fetchGraphQL={fetchGraphQL} />, {
46
+ request,
47
+ assets,
48
+ });
49
+
50
+ return response;
51
+ });
49
52
 
50
53
  export default router;
@@ -1,14 +1,9 @@
1
1
  import {
2
2
  createOptionalContext,
3
3
  createUseContextHook,
4
- createUseOptionalValueHook,
5
- } from '@quilted/quilt';
4
+ } from '@quilted/quilt/react/tools';
6
5
 
7
6
  export interface AppContext {}
8
7
 
9
8
  export const AppContextReact = createOptionalContext<AppContext>();
10
9
  export const useAppContext = createUseContextHook(AppContextReact);
11
-
12
- export function createUseAppContextHook<T>(hook: (context: AppContext) => T) {
13
- return createUseOptionalValueHook<T>(() => hook(useAppContext()));
14
- }
@@ -1,9 +1,8 @@
1
1
  import {
2
- TestGraphQL,
2
+ GraphQLTesting,
3
+ GraphQLController,
3
4
  createGraphQLSchema,
4
5
  createGraphQLFiller,
5
- createGraphQLController,
6
- type GraphQLController,
7
6
  } from '@quilted/quilt/graphql/testing';
8
7
 
9
8
  import schemaSource from '../graphql/schema.ts';
@@ -11,4 +10,4 @@ import schemaSource from '../graphql/schema.ts';
11
10
  export const schema = createGraphQLSchema(schemaSource);
12
11
  export const fillGraphQL = createGraphQLFiller(schema);
13
12
 
14
- export {createGraphQLController, TestGraphQL, type GraphQLController};
13
+ export {GraphQLController, GraphQLTesting};
@@ -1,13 +1,12 @@
1
- import {
2
- createRender,
3
- QuiltAppTesting,
4
- createTestRouter,
5
- } from '@quilted/quilt/testing';
1
+ import {createRender} from '@quilted/quilt/react/testing';
2
+ import {TestRouting, TestRouter} from '@quilted/quilt/navigate/testing';
3
+ import {Localization} from '@quilted/quilt/localize';
4
+
6
5
  import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
7
6
 
8
7
  import {AppContextReact} from '~/shared/context.ts';
9
8
 
10
- import {TestGraphQL, createGraphQLController} from '../graphql.ts';
9
+ import {GraphQLTesting, GraphQLController} from '../graphql.ts';
11
10
 
12
11
  import {RenderOptions, RenderContext, RenderActions} from './types.ts';
13
12
 
@@ -24,23 +23,25 @@ export const renderApp = createRender<
24
23
  // Create context that can be used by the `render` function, and referenced by test
25
24
  // authors on the `root.context` property. Context is used to share data between your
26
25
  // React tree and your test code, and is ideal for mocking out global context providers.
27
- context({router = createTestRouter(), graphql = createGraphQLController()}) {
26
+ context({router = new TestRouter(), graphql = new GraphQLController()}) {
28
27
  return {router, graphql, queryClient: new QueryClient()};
29
28
  },
30
29
  // Render all of our app-wide context providers around each component under test.
31
- render(element, context, {locale}) {
30
+ render(element, context, {locale = 'en'}) {
32
31
  const {router, graphql, queryClient} = context;
33
32
 
34
33
  return (
35
- <QuiltAppTesting routing={router} localization={locale}>
36
- <AppContextReact.Provider value={context}>
37
- <TestGraphQL controller={graphql}>
34
+ <Localization locale={locale}>
35
+ <TestRouting router={router}>
36
+ <GraphQLTesting controller={graphql}>
38
37
  <QueryClientProvider client={queryClient}>
39
- {element}
38
+ <AppContextReact.Provider value={context}>
39
+ {element}
40
+ </AppContextReact.Provider>
40
41
  </QueryClientProvider>
41
- </TestGraphQL>
42
- </AppContextReact.Provider>
43
- </QuiltAppTesting>
42
+ </GraphQLTesting>
43
+ </TestRouting>
44
+ </Localization>
44
45
  );
45
46
  },
46
47
  async afterRender(wrapper) {
@@ -1,12 +1,10 @@
1
- import type {createTestRouter} from '@quilted/quilt/testing';
1
+ import type {TestRouter} from '@quilted/quilt/navigate/testing';
2
2
  import type {QueryClient} from '@tanstack/react-query';
3
3
 
4
4
  import type {AppContext} from '~/shared/context.ts';
5
5
 
6
6
  import type {GraphQLController} from '../graphql.ts';
7
7
 
8
- type Router = ReturnType<typeof createTestRouter>;
9
-
10
8
  export interface RenderOptions {
11
9
  /**
12
10
  * A custom router to use for this component test. You can use a
@@ -14,7 +12,7 @@ export interface RenderOptions {
14
12
  * its navigation method to check that components navigate as
15
13
  * you expect.
16
14
  */
17
- readonly router?: Router;
15
+ readonly router?: TestRouter;
18
16
 
19
17
  /**
20
18
  * An object that controls the responses to GraphQL queries and mutations
@@ -47,7 +45,7 @@ export interface RenderContext extends AppContext {
47
45
  /**
48
46
  * The router used for this component test.
49
47
  */
50
- readonly router: Router;
48
+ readonly router: TestRouter;
51
49
 
52
50
  /**
53
51
  * The GraphQL controller used for this component test.
@@ -1,7 +1,7 @@
1
- import '@quilted/quilt/matchers';
1
+ import '@quilted/quilt/react/testing';
2
2
 
3
- export {createTestRouter} from '@quilted/quilt/testing';
3
+ export {TestRouter} from '@quilted/quilt/navigate/testing';
4
4
 
5
5
  export * from './render/types.ts';
6
6
  export {renderApp} from './render/render.tsx';
7
- export {fillGraphQL, createGraphQLController} from './graphql.ts';
7
+ export {fillGraphQL, GraphQLController} from './graphql.ts';
@@ -1,38 +1,47 @@
1
- import {
2
- QuiltApp,
3
- useRoutes,
4
- type PropsWithChildren,
5
- useInitialUrl,
6
- } from '@quilted/quilt';
1
+ import {useMemo} from 'react';
2
+
3
+ import {HTML} from '@quilted/quilt/html';
4
+ import {Routing, useRoutes, useInitialUrl} from '@quilted/quilt/navigate';
5
+ import {Localization, useLocaleFromEnvironment} from '@quilted/quilt/localize';
6
+ import {type PropsWithChildren} from '@quilted/quilt/react/tools';
7
7
 
8
8
  import {httpBatchLink} from '@trpc/client';
9
9
  import {QueryClient} from '@tanstack/react-query';
10
10
  import {ReactQueryContext} from '@quilted/react-query';
11
11
 
12
+ import {Head} from './foundation/html.ts';
13
+ import {Headers} from './foundation/http.ts';
14
+ import {Frame} from './foundation/frame.ts';
15
+
16
+ import {Start} from './features/start.ts';
17
+
18
+ import {trpc} from './shared/trpc.ts';
12
19
  import {
13
20
  AppContextReact,
14
21
  type AppContext as AppContextType,
15
- } from '~/shared/context.ts';
16
- import {trpc} from '~/shared/trpc.ts';
22
+ } from './shared/context.ts';
17
23
 
18
- import {Http} from './foundation/Http.tsx';
19
- import {Head} from './foundation/Head.tsx';
20
- import {Metrics} from './foundation/Metrics.tsx';
21
-
22
- import {Start} from './features/Start.tsx';
23
- import {useMemo} from 'react';
24
-
25
- export interface Props extends AppContextType {}
24
+ export interface AppProps extends AppContextType {}
26
25
 
27
26
  // The root component for your application. You will typically render any
28
27
  // app-wide context in this component.
29
- export default function App(props: Props) {
28
+ export function App(props: AppProps) {
29
+ const locale = useLocaleFromEnvironment() ?? 'en';
30
+
30
31
  return (
31
- <QuiltApp http={<Http />} html={<Head />}>
32
- <AppContext {...props}>
33
- <Routes />
34
- </AppContext>
35
- </QuiltApp>
32
+ <HTML>
33
+ <Localization locale={locale}>
34
+ <Routing>
35
+ <AppContext {...props}>
36
+ <Headers />
37
+ <Head />
38
+ <Frame>
39
+ <Routes />
40
+ </Frame>
41
+ </AppContext>
42
+ </Routing>
43
+ </Localization>
44
+ </HTML>
36
45
  );
37
46
  }
38
47
 
@@ -45,10 +54,7 @@ function Routes() {
45
54
  }
46
55
 
47
56
  // This component renders any app-wide context.
48
- function AppContext({
49
- children,
50
- ...appContext
51
- }: PropsWithChildren<AppContextType>) {
57
+ function AppContext({children, ...context}: PropsWithChildren<AppProps>) {
52
58
  const initialUrl = useInitialUrl();
53
59
 
54
60
  const {queryClient, trpcClient} = useMemo(() => {
@@ -65,12 +71,12 @@ function AppContext({
65
71
  }, [initialUrl]);
66
72
 
67
73
  return (
68
- <AppContextReact.Provider value={appContext}>
69
- <Metrics>
70
- <trpc.Provider client={trpcClient} queryClient={queryClient}>
71
- <ReactQueryContext client={queryClient}>{children}</ReactQueryContext>
72
- </trpc.Provider>
73
- </Metrics>
74
- </AppContextReact.Provider>
74
+ <trpc.Provider client={trpcClient} queryClient={queryClient}>
75
+ <ReactQueryContext client={queryClient}>
76
+ <AppContextReact.Provider value={context}>
77
+ {children}
78
+ </AppContextReact.Provider>
79
+ </ReactQueryContext>
80
+ </trpc.Provider>
75
81
  );
76
82
  }
@@ -1,4 +1,4 @@
1
- import '@quilted/quilt/global';
1
+ import '@quilted/quilt/globals';
2
2
  import {hydrateRoot} from 'react-dom/client';
3
3
  import {httpBatchLink} from '@trpc/client';
4
4
 
@@ -1,12 +1,12 @@
1
1
  import {describe, it, expect} from '@quilted/quilt/testing';
2
2
 
3
- import {renderWithAppContext} from '~/tests/render.tsx';
3
+ import {renderApp} from '~/tests/render.ts';
4
4
 
5
5
  import Start from './Start.tsx';
6
6
 
7
7
  describe('<Start />', () => {
8
8
  it('includes a welcome message', async () => {
9
- const start = await renderWithAppContext(<Start />);
9
+ const start = await renderApp(<Start />);
10
10
  expect(start).toContainReactText('Hello world!');
11
11
  });
12
12
  });
@@ -0,0 +1,9 @@
1
+ import {trpc} from '~/shared/trpc.ts';
2
+
3
+ import styles from './Start.module.css';
4
+
5
+ export default function Start() {
6
+ const [data] = trpc.message.useSuspenseQuery('world');
7
+
8
+ return <div className={styles.Start}>{data}</div>;
9
+ }
@@ -0,0 +1,5 @@
1
+ import {createAsyncComponent} from '@quilted/quilt/async';
2
+
3
+ export const Start = createAsyncComponent(
4
+ () => import('./start/Start/Start.tsx'),
5
+ );
@@ -0,0 +1,14 @@
1
+ *,
2
+ *::before,
3
+ *::after {
4
+ box-sizing: border-box;
5
+ }
6
+
7
+ html,
8
+ body {
9
+ margin: 0;
10
+ }
11
+
12
+ .Frame {
13
+ padding: 1rem;
14
+ }
@@ -0,0 +1,7 @@
1
+ import type {PropsWithChildren} from '@quilted/quilt/react/tools';
2
+
3
+ import styles from './Frame.module.css';
4
+
5
+ export function Frame({children}: PropsWithChildren) {
6
+ return <div className={styles.Frame}>{children}</div>;
7
+ }
@@ -0,0 +1 @@
1
+ export {Frame} from './frame/Frame.tsx';
@@ -1,13 +1,13 @@
1
- import {Viewport, SearchRobots} from '@quilted/quilt/html';
2
1
  import {describe, it, expect} from '@quilted/quilt/testing';
2
+ import {Viewport, SearchRobots} from '@quilted/quilt/html';
3
3
 
4
- import {renderWithAppContext} from '~/tests/render.tsx';
4
+ import {renderApp} from '~/tests/render.tsx';
5
5
 
6
6
  import {Head} from './Head.tsx';
7
7
 
8
8
  describe('<Head />', () => {
9
9
  it('includes a responsive viewport tag', async () => {
10
- const head = await renderWithAppContext(<Head />);
10
+ const head = await renderApp(<Head />);
11
11
 
12
12
  expect(head).toContainReactComponent(Viewport, {
13
13
  cover: true,
@@ -15,7 +15,7 @@ describe('<Head />', () => {
15
15
  });
16
16
 
17
17
  it('prevents search robots from indexing the application', async () => {
18
- const head = await renderWithAppContext(<Head />);
18
+ const head = await renderApp(<Head />);
19
19
 
20
20
  expect(head).toContainReactComponent(SearchRobots, {
21
21
  index: false,
@@ -0,0 +1 @@
1
+ export {Head} from './html/Head.tsx';
@@ -1,23 +1,23 @@
1
- import {CacheControl, ContentSecurityPolicy} from '@quilted/quilt/http';
2
1
  import {describe, it, expect} from '@quilted/quilt/testing';
2
+ import {CacheControl, ContentSecurityPolicy} from '@quilted/quilt/http';
3
3
 
4
- import {renderWithAppContext} from '~/tests/render.tsx';
4
+ import {renderApp} from '~/tests/render.tsx';
5
5
 
6
- import {Http} from './Http.tsx';
6
+ import {Headers} from './Headers.tsx';
7
7
 
8
- describe('<Http />', () => {
8
+ describe('<Headers />', () => {
9
9
  it('does not cache the response', async () => {
10
- const http = await renderWithAppContext(<Http />);
10
+ const headers = await renderApp(<Headers />);
11
11
 
12
- expect(http).toContainReactComponent(CacheControl, {
12
+ expect(headers).toContainReactComponent(CacheControl, {
13
13
  cache: false,
14
14
  });
15
15
  });
16
16
 
17
17
  it('adds a content security policy with a strict default policy', async () => {
18
- const http = await renderWithAppContext(<Http />);
18
+ const headers = await renderApp(<Headers />);
19
19
 
20
- expect(http).toContainReactComponent(ContentSecurityPolicy, {
20
+ expect(headers).toContainReactComponent(ContentSecurityPolicy, {
21
21
  defaultSources: ["'self'"],
22
22
  });
23
23
  });
@@ -1,5 +1,5 @@
1
1
  import Env from '@quilted/quilt/env';
2
- import {useCurrentUrl} from '@quilted/quilt';
2
+ import {useInitialUrl} from '@quilted/quilt/navigate';
3
3
  import {
4
4
  CacheControl,
5
5
  ResponseHeader,
@@ -14,8 +14,8 @@ import {
14
14
  // wherever in your application you can read that state.
15
15
  //
16
16
  // @see https://github.com/lemonmade/quilt/blob/main/documentation/features/http.md
17
- export function Http() {
18
- const isHttps = useCurrentUrl().protocol === 'https:';
17
+ export function Headers() {
18
+ const isHttps = useInitialUrl().protocol === 'https:';
19
19
 
20
20
  return (
21
21
  <>
@@ -0,0 +1 @@
1
+ export {Headers} from './http/Headers.tsx';
@@ -1,4 +1,4 @@
1
- import '@quilted/quilt/global';
1
+ import '@quilted/quilt/globals';
2
2
  import {createRequestRouter, createServerRender} from '@quilted/quilt/server';
3
3
  import {createBrowserAssets} from '@quilted/quilt/magic/assets';
4
4
  import {createDirectClient} from '@quilted/trpc/server';
@@ -1,14 +1,9 @@
1
1
  import {
2
2
  createOptionalContext,
3
3
  createUseContextHook,
4
- createUseOptionalValueHook,
5
- } from '@quilted/quilt';
4
+ } from '@quilted/quilt/react/tools';
6
5
 
7
6
  export interface AppContext {}
8
7
 
9
8
  export const AppContextReact = createOptionalContext<AppContext>();
10
9
  export const useAppContext = createUseContextHook(AppContextReact);
11
-
12
- export function createUseAppContextHook<T>(hook: (context: AppContext) => T) {
13
- return createUseOptionalValueHook<T>(() => hook(useAppContext()));
14
- }
@@ -1,8 +1,7 @@
1
- import {
2
- createRender,
3
- QuiltAppTesting,
4
- createTestRouter,
5
- } from '@quilted/quilt/testing';
1
+ import {createRender} from '@quilted/quilt/react/testing';
2
+ import {TestRouting, TestRouter} from '@quilted/quilt/navigate/testing';
3
+ import {Localization} from '@quilted/quilt/localize';
4
+
6
5
  import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
7
6
 
8
7
  import {trpc} from '~/shared/trpc.ts';
@@ -23,23 +22,25 @@ export const renderApp = createRender<
23
22
  // Create context that can be used by the `render` function, and referenced by test
24
23
  // authors on the `root.context` property. Context is used to share data between your
25
24
  // React tree and your test code, and is ideal for mocking out global context providers.
26
- context({router = createTestRouter()}) {
25
+ context({router = new TestRouter()}) {
27
26
  return {router, trpc: trpc.createClient(), queryClient: new QueryClient()};
28
27
  },
29
28
  // Render all of our app-wide context providers around each component under test.
30
- render(element, context, {locale}) {
29
+ render(element, context, {locale = 'en'}) {
31
30
  const {router, trpc: trpcClient, queryClient} = context;
32
31
 
33
32
  return (
34
- <QuiltAppTesting routing={router} localization={locale}>
35
- <AppContextReact.Provider value={context}>
36
- <trpc.Provider client={trpcClient} queryClient={queryClient}>
37
- <QueryClientProvider client={queryClient}>
38
- {element}
39
- </QueryClientProvider>
40
- </trpc.Provider>
41
- </AppContextReact.Provider>
42
- </QuiltAppTesting>
33
+ <Localization locale={locale}>
34
+ <TestRouting router={router}>
35
+ <AppContextReact.Provider value={context}>
36
+ <trpc.Provider client={trpcClient} queryClient={queryClient}>
37
+ <QueryClientProvider client={queryClient}>
38
+ {element}
39
+ </QueryClientProvider>
40
+ </trpc.Provider>
41
+ </AppContextReact.Provider>
42
+ </TestRouting>
43
+ </Localization>
43
44
  );
44
45
  },
45
46
  async afterRender() {
@@ -1,6 +1,6 @@
1
- import {createRequestRouter} from '@quilted/quilt/request-router';
1
+ import {RequestRouter} from '@quilted/quilt/request-router';
2
2
 
3
- const app = createRequestRouter();
3
+ const app = new RequestRouter();
4
4
 
5
5
  app.get('/', () => new Response('Hello, world!'));
6
6
 
@@ -1,12 +0,0 @@
1
- import {usePerformanceNavigation} from '@quilted/quilt';
2
-
3
- import styles from './Start.module.css';
4
-
5
- export default function Start() {
6
- // This hook indicates that the page has loaded. It is used as part of Quilt’s
7
- // navigation performance tracking feature. If you have disabled this feature,
8
- // you can remove this hook.
9
- usePerformanceNavigation();
10
-
11
- return <div className={styles.Start}>Hello world!</div>;
12
- }
@@ -1,3 +0,0 @@
1
- import {createAsyncComponent} from '@quilted/quilt';
2
-
3
- export const Start = createAsyncComponent(() => import('./Start/Start.tsx'));
@@ -1 +0,0 @@
1
- export {Head} from './Head/Head.tsx';
@@ -1 +0,0 @@
1
- export {Http} from './Http/Http.tsx';
@@ -1,23 +0,0 @@
1
- import {
2
- usePerformanceNavigationEvent,
3
- type PropsWithChildren,
4
- } from '@quilted/quilt';
5
- import Env from '@quilted/quilt/env';
6
-
7
- // This component records metrics about your application.
8
- export function Metrics({children}: PropsWithChildren) {
9
- usePerformanceNavigationEvent(async (navigation) => {
10
- if (Env.MODE === 'development') {
11
- // eslint-disable-next-line no-console
12
- console.log('Navigation:');
13
- // eslint-disable-next-line no-console
14
- console.log(navigation);
15
- return;
16
- }
17
-
18
- // If you have a service that collects metrics, you can send navigation
19
- // data to them here.
20
- });
21
-
22
- return <>{children}</>;
23
- }