remix 3.0.0-beta.5 → 3.0.0-beta.6

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 (59) hide show
  1. package/README.md +4 -2
  2. package/dist/assets/types/hmr.d.ts +2 -0
  3. package/dist/cli-entry.js +1 -1
  4. package/dist/data-table/cli.d.ts +2 -0
  5. package/dist/data-table/cli.d.ts.map +1 -0
  6. package/dist/data-table/cli.js +2 -0
  7. package/dist/node-hmr/runtime.d.ts +2 -0
  8. package/dist/node-hmr/runtime.d.ts.map +1 -0
  9. package/dist/node-hmr/runtime.js +2 -0
  10. package/dist/node-hmr/types.d.ts +2 -0
  11. package/dist/node-hmr.d.ts +2 -0
  12. package/dist/node-hmr.d.ts.map +1 -0
  13. package/dist/node-hmr.js +2 -0
  14. package/dist/ui/dev/refresh.d.ts +2 -0
  15. package/dist/ui/dev/refresh.d.ts.map +1 -0
  16. package/dist/ui/dev/refresh.js +2 -0
  17. package/dist/ui-hmr/assets.d.ts +2 -0
  18. package/dist/ui-hmr/assets.d.ts.map +1 -0
  19. package/dist/ui-hmr/assets.js +2 -0
  20. package/dist/ui-hmr/node.d.ts +3 -0
  21. package/dist/ui-hmr/node.d.ts.map +1 -0
  22. package/dist/ui-hmr/node.js +3 -0
  23. package/dist/ui-hmr/runtime/browser.d.ts +2 -0
  24. package/dist/ui-hmr/runtime/browser.d.ts.map +1 -0
  25. package/dist/ui-hmr/runtime/browser.js +2 -0
  26. package/dist/ui-hmr/runtime/server.d.ts +2 -0
  27. package/dist/ui-hmr/runtime/server.d.ts.map +1 -0
  28. package/dist/ui-hmr/runtime/server.js +2 -0
  29. package/dist/ui-hmr.d.ts +2 -0
  30. package/dist/ui-hmr.d.ts.map +1 -0
  31. package/dist/ui-hmr.js +2 -0
  32. package/package.json +78 -126
  33. package/src/assets/README.md +322 -56
  34. package/src/assets/types/hmr.d.ts +2 -0
  35. package/src/cli/README.md +105 -1
  36. package/src/cookie/README.md +4 -4
  37. package/src/data-table/README.md +202 -68
  38. package/src/data-table/cli.ts +2 -0
  39. package/src/data-table-mysql/README.md +22 -18
  40. package/src/data-table-postgres/README.md +14 -14
  41. package/src/data-table-sqlite/README.md +38 -20
  42. package/src/fetch-proxy/README.md +25 -0
  43. package/src/node-fetch-server/README.md +11 -11
  44. package/src/node-hmr/README.md +307 -0
  45. package/src/node-hmr/runtime.ts +2 -0
  46. package/src/node-hmr/types.d.ts +2 -0
  47. package/src/node-hmr.ts +2 -0
  48. package/src/route-pattern/README.md +91 -8
  49. package/src/session-middleware/README.md +9 -7
  50. package/src/test/README.md +161 -115
  51. package/src/ui/README.md +74 -1
  52. package/src/ui/dev/refresh.ts +2 -0
  53. package/src/ui/test/README.md +151 -60
  54. package/src/ui-hmr/README.md +119 -0
  55. package/src/ui-hmr/assets.ts +2 -0
  56. package/src/ui-hmr/node.ts +3 -0
  57. package/src/ui-hmr/runtime/browser.ts +2 -0
  58. package/src/ui-hmr/runtime/server.ts +2 -0
  59. package/src/ui-hmr.ts +2 -0
@@ -1,104 +1,195 @@
1
1
  # Test
2
2
 
3
- When writing tests, use `root.flush()` to synchronously execute all pending updates and tasks. This ensures the DOM and component state are fully synchronized before making assertions.
3
+ Use `render` from `remix/ui/test` as the primary way to test components in a live browser through a `remix/test` "browser" test (`*.test.browser.tsx`). It creates a DOM container, renders and flushes the initial component tree, and returns helpers for querying, interacting with, and cleaning up the rendered output.
4
4
 
5
- ## Basic Testing Pattern
6
-
7
- The main use case is flushing after events that call `handle.update()`. Since updates are asynchronous, you need to flush to ensure the DOM reflects the changes:
5
+ ## Rendering Components
8
6
 
9
7
  ```tsx
8
+ import { expect } from 'remix/assert'
9
+ import { describe, it } from 'remix/test'
10
+ import { on, type Handle } from 'remix/ui'
11
+ import { render } from 'remix/ui/test'
12
+
10
13
  function Counter(handle: Handle) {
11
14
  let count = 0
12
15
 
13
16
  return () => (
14
- <button
15
- mix={[
16
- on('click', () => {
17
- count++
18
- handle.update()
19
- }),
20
- ]}
21
- >
22
- Count: {count}
23
- </button>
17
+ <div>
18
+ <button
19
+ data-action="increment"
20
+ mix={[
21
+ on('click', () => {
22
+ count++
23
+ handle.update()
24
+ }),
25
+ ]}
26
+ >
27
+ Increment
28
+ </button>
29
+ <output data-testid="count">{count}</output>
30
+ </div>
24
31
  )
25
32
  }
26
33
 
27
- // In your test
28
- let container = document.createElement('div')
29
- let root = createRoot(container)
34
+ describe('Counter', () => {
35
+ it('increments the count', async (t) => {
36
+ let { $, act, cleanup } = render(<Counter />)
37
+ t.after(cleanup)
30
38
 
31
- root.render(<Counter />)
32
- root.flush() // Ensure initial render completes
39
+ expect($('[data-testid="count"]')?.textContent).toBe('0')
33
40
 
34
- let button = container.querySelector('button')
35
- button.click() // Triggers handle.update()
36
- root.flush() // Flush to apply the update
41
+ await act(() => $('[data-action="increment"]')?.click())
37
42
 
38
- expect(container.textContent).toBe('Count: 1')
43
+ expect($('[data-testid="count"]')?.textContent).toBe('1')
44
+ })
45
+ })
39
46
  ```
40
47
 
41
- ## Why Flush After Initial Render?
48
+ The initial render is already flushed, so the DOM and event listeners are ready when `render`
49
+ returns. Wrap interactions that may update component state in `act` and always await it. `act`
50
+ waits for the callback and then flushes pending component updates before the next assertion.
51
+
52
+ ### Testing Async Operations
42
53
 
43
- You should also flush after the initial `root.render()` to ensure event listeners are attached and the DOM is ready for interaction:
54
+ When an interaction starts an async operation, await that operation inside `act` so updates queued
55
+ after it resolves are flushed before making assertions:
44
56
 
45
57
  ```tsx
46
- let root = createRoot(container)
47
- root.render(<MyComponent />)
48
- root.flush() // Event listeners now attached
58
+ function UserLoader(handle: Handle<{ loadUser(): Promise<{ name: string }> }>) {
59
+ let name = 'No user loaded'
49
60
 
50
- // Safe to interact
51
- container.querySelector('button').click()
61
+ return () => (
62
+ <div>
63
+ <button
64
+ mix={[
65
+ on('click', async () => {
66
+ let user = await handle.props.loadUser()
67
+ name = user.name
68
+ handle.update()
69
+ }),
70
+ ]}
71
+ >
72
+ Load user
73
+ </button>
74
+ <output>{name}</output>
75
+ </div>
76
+ )
77
+ }
78
+
79
+ it('loads a user', async (t) => {
80
+ let userPromise = Promise.resolve({ name: 'Ada' })
81
+ let { $, act, cleanup } = render(<UserLoader loadUser={() => userPromise} />)
82
+ t.after(cleanup)
83
+
84
+ await act(async () => {
85
+ $('button')?.click()
86
+ await userPromise
87
+ })
88
+
89
+ expect($('output')?.textContent).toBe('Ada')
90
+ })
52
91
  ```
53
92
 
54
- ## Testing Async Operations
93
+ ### Querying Rendered Output
55
94
 
56
- For components with async operations in `queueTask`, flush after each step:
95
+ The returned query helpers are scoped to the rendered container so you don't have to worry about false positives outside of the rendered component:
57
96
 
58
97
  ```tsx
59
- function AsyncLoader(handle: Handle) {
60
- let data: string | null = null
61
-
62
- handle.queueTask(async (signal) => {
63
- let response = await fetch('/api/data', { signal })
64
- let json = await response.json()
65
- if (signal.aborted) return
66
- data = json.value
67
- handle.update()
68
- })
98
+ let { $, $$, container, cleanup } = render(
99
+ <nav>
100
+ <a href="/one">One</a>
101
+ <a href="/two">Two</a>
102
+ </nav>,
103
+ )
69
104
 
70
- return () => <div>{data ?? 'Loading...'}</div>
71
- }
105
+ let nav = $('nav') // container.querySelector('nav')
106
+ let links = $$('a') // container.querySelectorAll('a')
72
107
 
73
- // In your test (with mocked fetch)
74
- let root = createRoot(container)
75
- root.render(<AsyncLoader />)
76
- root.flush()
108
+ expect(nav).toBeTruthy()
109
+ expect(links).toHaveLength(2)
110
+ expect(container.textContent).toContain('One')
77
111
 
78
- expect(container.textContent).toBe('Loading...')
112
+ cleanup()
113
+ ```
79
114
 
80
- // After fetch resolves
81
- await waitForFetch()
82
- root.flush()
115
+ Use `$` for the first matching element, `$$` for all matching elements, and `container` when a
116
+ DOM assertion does not fit a selector.
83
117
 
84
- expect(container.textContent).toBe('Expected data')
118
+ ### Cleaning Up
119
+
120
+ Register `cleanup` with the test context so it always runs, including when an assertion fails:
121
+
122
+ ```tsx
123
+ it('renders a dialog', (t) => {
124
+ let { $, cleanup } = render(<Dialog />)
125
+ t.after(cleanup)
126
+
127
+ expect($('[role="dialog"]')).toBeTruthy()
128
+ })
85
129
  ```
86
130
 
87
- ## Testing Component Removal
131
+ `cleanup` disposes the root and removes its container from the document. You can call it directly
132
+ when a test needs to assert cleanup behavior.
133
+
134
+ ### Rendering Into an Existing Container
88
135
 
89
- Use `root.dispose()` to clean up and verify cleanup behavior:
136
+ Pass a container when the test needs a specific DOM context:
90
137
 
91
138
  ```tsx
139
+ let container = document.createElement('section')
140
+ document.body.appendChild(container)
141
+
142
+ let result = render(<MyComponent />, { container })
143
+
144
+ expect(result.container).toBe(container)
145
+ result.cleanup()
146
+ ```
147
+
148
+ ## Advanced: Flushing Manually
149
+
150
+ Most component tests should use `render` and `act`. For lower-level runtime tests that need direct
151
+ control over rendering or scheduling, use the returned `root` and call `root.flush()` after an
152
+ operation that queues work:
153
+
154
+ ```tsx
155
+ let { root, container, cleanup } = render(<MyComponent value="first" />)
156
+
157
+ root.render(<MyComponent value="second" />)
158
+ root.flush()
159
+
160
+ expect(container.textContent).toContain('second')
161
+ cleanup()
162
+ ```
163
+
164
+ You can also create and manage a root directly:
165
+
166
+ ```tsx
167
+ import { createRoot } from 'remix/ui'
168
+
169
+ let container = document.createElement('div')
92
170
  let root = createRoot(container)
171
+
93
172
  root.render(<MyComponent />)
94
- root.flush()
173
+ root.flush() // Complete the initial render and attach event listeners
95
174
 
96
- // Verify setup behavior
97
- expect(container.querySelector('.content')).toBeTruthy()
175
+ container.querySelector('button')?.click()
176
+ root.flush() // Apply updates queued by the interaction
98
177
 
99
- // Remove and verify cleanup
100
178
  root.dispose()
101
- expect(container.innerHTML).toBe('')
179
+ ```
180
+
181
+ Manual flushing is also useful after an async operation resolves outside an `act` callback:
182
+
183
+ ```tsx
184
+ root.render(<AsyncLoader />)
185
+ root.flush()
186
+
187
+ expect(container.textContent).toBe('Loading...')
188
+
189
+ await waitForFetch()
190
+ root.flush()
191
+
192
+ expect(container.textContent).toBe('Expected data')
102
193
  ```
103
194
 
104
195
  ## See Also
@@ -0,0 +1,119 @@
1
+ # ui-hmr
2
+
3
+ Hot module replacement transforms for Remix UI components, with integrations for Node and `remix/assets`.
4
+
5
+ `ui-hmr` rewrites supported Remix UI component modules so they can use the standard `import.meta.hot` APIs provided by packages like [`assets`](https://github.com/remix-run/remix/tree/main/packages/assets) and [`node-hmr`](https://github.com/remix-run/remix/tree/main/packages/node-hmr).
6
+
7
+ ## Features
8
+
9
+ - **Stable Components** - Keep component identity stable while swapping implementations
10
+ - **Remount Fallbacks** - Mark components stale when their setup scope changes
11
+ - **Node Module Hooks** - Transform server component modules through Node's module customization hooks API
12
+ - **Assets Loader** - Transform component modules for the browser through `remix/assets`
13
+
14
+ ## Installation
15
+
16
+ ```sh
17
+ npm i remix
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ Use `remix/ui-hmr/node` as a Node import hook for server modules:
23
+
24
+ ```sh
25
+ node --import remix/node-tsx --import remix/ui-hmr/node ./server.ts
26
+ ```
27
+
28
+ Use `uiHmr()` from `remix/ui-hmr/assets` with `remix/assets` for browser modules:
29
+
30
+ ```ts
31
+ import { createAssetServer } from 'remix/assets'
32
+ import { uiHmr } from 'remix/ui-hmr/assets'
33
+
34
+ let isDevelopment = process.env.NODE_ENV === 'development'
35
+
36
+ let assetServer = createAssetServer({
37
+ basePath: '/assets',
38
+ fileMap: { '/app/*path': 'app/*path' },
39
+ allowFiles: ['app/routes.ts', 'app/**/public/**'],
40
+ allowPackages: ['remix'],
41
+ denyFiles: ['app/**/*.test.*'],
42
+ hmr: isDevelopment
43
+ ? async () => (await import('remix/node-hmr/runtime')).createBrowserHmrChannel()
44
+ : undefined,
45
+ scripts: {
46
+ loaders: isDevelopment ? [uiHmr()] : undefined,
47
+ },
48
+ watch: isDevelopment,
49
+ })
50
+ ```
51
+
52
+ ## Direct Transforms
53
+
54
+ Use the direct transform APIs when you are writing your own loader, Node module hooks, or build integration.
55
+
56
+ ```ts
57
+ import { transformComponentsForBrowser } from 'remix/ui-hmr'
58
+
59
+ let result = transformComponentsForBrowser(source, {
60
+ importSource: 'remix',
61
+ moduleUrl: '/assets/app/routes.tsx',
62
+ })
63
+
64
+ if (result.transformed) {
65
+ console.log(result.componentNames)
66
+ }
67
+ ```
68
+
69
+ `transformComponentsForBrowser(source, options)` rewrites browser component modules and emits `import.meta.hot.accept()` code for browser updates. The direct transform uses `importSource` to derive imports for the UI refresh runtime and browser HMR runtime.
70
+
71
+ ```ts
72
+ import { transformComponentsForServer } from 'remix/ui-hmr'
73
+
74
+ let result = transformComponentsForServer(source, {
75
+ importSource: 'remix',
76
+ moduleUrl: 'file:///app/routes.tsx',
77
+ })
78
+ ```
79
+
80
+ `transformComponentsForServer(source, options)` rewrites server component modules and registers updated component implementations for the current module URL. The direct transform uses `importSource` to derive imports for the server HMR runtime.
81
+
82
+ Both transforms return:
83
+
84
+ ```ts
85
+ type ComponentsHmrTransformResult = {
86
+ code: string
87
+ componentNames: string[]
88
+ map: string | null
89
+ transformed: boolean
90
+ }
91
+ ```
92
+
93
+ Pass `sourceMap: true` to generate a source map.
94
+
95
+ Use `importSource` to define where injected imports come from, typically either `remix` or `@remix-run`:
96
+
97
+ ```ts
98
+ transformComponentsForBrowser(source, {
99
+ importSource: 'remix',
100
+ moduleUrl: '/assets/app/routes.tsx',
101
+ })
102
+
103
+ transformComponentsForServer(source, {
104
+ importSource: 'remix',
105
+ moduleUrl: 'file:///app/routes.tsx',
106
+ })
107
+ ```
108
+
109
+ `importSource: 'remix'` generates imports from `remix/ui` and `remix/ui-hmr`. `importSource: '@remix-run'` generates imports from `@remix-run/ui` and `@remix-run/ui-hmr`. Custom import sources follow the same nested import layout.
110
+
111
+ ## Related Packages
112
+
113
+ - [`assets`](https://github.com/remix-run/remix/tree/main/packages/assets) - Runs loaders while compiling assets
114
+ - [`node-hmr`](https://github.com/remix-run/remix/tree/main/packages/node-hmr) - Provides the server-side `import.meta.hot` runtime
115
+ - [`ui`](https://github.com/remix-run/remix/tree/main/packages/ui) - Component APIs transformed by `ui-hmr`
116
+
117
+ ## License
118
+
119
+ See [LICENSE](https://github.com/remix-run/remix/blob/main/LICENSE)
@@ -0,0 +1,2 @@
1
+ // IMPORTANT: This file is auto-generated, please do not edit manually.
2
+ export * from '@remix-run/ui-hmr/assets'
@@ -0,0 +1,3 @@
1
+ // IMPORTANT: This file is auto-generated, please do not edit manually.
2
+ import '@remix-run/ui-hmr/node'
3
+ export {}
@@ -0,0 +1,2 @@
1
+ // IMPORTANT: This file is auto-generated, please do not edit manually.
2
+ export * from '@remix-run/ui-hmr/runtime/browser'
@@ -0,0 +1,2 @@
1
+ // IMPORTANT: This file is auto-generated, please do not edit manually.
2
+ export * from '@remix-run/ui-hmr/runtime/server'
package/src/ui-hmr.ts ADDED
@@ -0,0 +1,2 @@
1
+ // IMPORTANT: This file is auto-generated, please do not edit manually.
2
+ export * from '@remix-run/ui-hmr'