Commit 0cc9ade
fix: React hooks null reference error (#211)
* fix: resolve React hooks null reference error and update demo dependencies
This commit fixes the "Cannot read properties of null (reading 'useState')" error
that occurred when using the library with Next.js.
Changes:
- Updated Vite config to explicitly set jsxRuntime: 'automatic' for proper JSX transformation
- Updated demo to use Next.js 15.5.6 (from 14.2.33) for better React 19 support
- Updated demo React to 19.0.0 (from 18.2.0) to match library peer dependencies
- Added .eslintrc.json to demo for Next.js 15 ESLint compatibility
The root cause was a combination of:
1. Implicit JSX runtime configuration in Vite
2. Outdated Next.js version with React version mismatch
3. Module resolution issues between the library build and Next.js runtime
The fix ensures:
- Proper React externalization in the library build
- Compatible versions across the demo stack
- Correct JSX transformation for library consumers
Tested with:
- npm run build (library): ✅ Successful
- npm run build (demo): ✅ Successful (3/3 pages generated)
- React hooks now properly resolve at runtime
* docs: document local library development workflow in CONTRIBUTING.md
Added comprehensive "Development Setup" section to explain:
- Repository structure (library root + demo/ folder)
- How the demo uses `file:..` to reference the local library
- Complete getting started guide for new contributors
- Step-by-step workflow for making and testing changes
- Important notes about the local development approach
This documentation helps contributors understand:
- Why demo uses `file:..` instead of the published npm version
- How to test library changes in the demo before publishing
- The rebuild workflow required when modifying library source
Related to the React hooks null error fix, this ensures contributors
know how to properly set up and test the local development environment.
* refactor: switch demo to use published npm package by default
Changes the demo application to use the published "react-lite-youtube-embed"
package instead of the local build, while documenting how contributors can
switch to local development mode when needed.
Changes:
- Updated demo/package.json to use "react-lite-youtube-embed": "*"
- Updated all imports from "@ibrahimcesar/react-lite-youtube-embed" to "react-lite-youtube-embed"
- Updated next.config.js transpilePackages to use new package name
- Rewrote CONTRIBUTING.md Development Setup section:
- Demo uses published package by default (showcases what users install)
- Added instructions for switching to local dev with "file:.." when testing changes
- Emphasized reverting to published package before committing
- Clearer workflow: getting started, running demo, local development, testing
Why this change:
- Demo showcases the actual package users will install from npm
- Contributors can still test locally by temporarily using "file:.."
- Ensures demo always represents the published user experience
- Reduces confusion about which version is being used
Local development workflow:
1. Change package.json to use "file:.." when testing library changes
2. Always revert to "react-lite-youtube-embed": "*" before committing
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent ee837b6 commit 0cc9ade
File tree
7 files changed
+754
-202
lines changed- demo
- pages
7 files changed
+754
-202
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
13 | 25 | | |
14 | 26 | | |
15 | 27 | | |
16 | 28 | | |
17 | | - | |
| 29 | + | |
18 | 30 | | |
19 | 31 | | |
20 | 32 | | |
21 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
22 | 39 | | |
23 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
24 | 44 | | |
25 | | - | |
| 45 | + | |
26 | 46 | | |
27 | | - | |
| 47 | + | |
28 | 48 | | |
29 | | - | |
30 | | - | |
31 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
32 | 79 | | |
33 | 80 | | |
34 | | - | |
| 81 | + | |
35 | 82 | | |
| 83 | + | |
| 84 | + | |
36 | 85 | | |
37 | 86 | | |
38 | 87 | | |
39 | 88 | | |
40 | | - | |
| 89 | + | |
41 | 90 | | |
42 | | - | |
43 | | - | |
44 | | - | |
| 91 | + | |
45 | 92 | | |
46 | 93 | | |
47 | 94 | | |
48 | 95 | | |
49 | | - | |
| 96 | + | |
50 | 97 | | |
51 | 98 | | |
52 | 99 | | |
53 | 100 | | |
54 | 101 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 102 | + | |
59 | 103 | | |
60 | 104 | | |
61 | 105 | | |
62 | 106 | | |
63 | | - | |
| 107 | + | |
64 | 108 | | |
65 | | - | |
| 109 | + | |
66 | 110 | | |
67 | | - | |
| 111 | + | |
68 | 112 | | |
69 | 113 | | |
70 | 114 | | |
71 | 115 | | |
72 | 116 | | |
73 | | - | |
| 117 | + | |
74 | 118 | | |
75 | 119 | | |
76 | 120 | | |
77 | 121 | | |
78 | 122 | | |
79 | | - | |
| 123 | + | |
80 | 124 | | |
81 | 125 | | |
82 | 126 | | |
83 | 127 | | |
84 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
85 | 138 | | |
86 | 139 | | |
87 | 140 | | |
88 | 141 | | |
89 | 142 | | |
90 | | - | |
| 143 | + | |
91 | 144 | | |
92 | 145 | | |
93 | 146 | | |
| |||
96 | 149 | | |
97 | 150 | | |
98 | 151 | | |
99 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
100 | 158 | | |
101 | 159 | | |
102 | 160 | | |
103 | 161 | | |
104 | | - | |
| 162 | + | |
105 | 163 | | |
106 | 164 | | |
107 | 165 | | |
108 | 166 | | |
109 | | - | |
| 167 | + | |
110 | 168 | | |
111 | 169 | | |
112 | 170 | | |
113 | 171 | | |
114 | | - | |
| 172 | + | |
115 | 173 | | |
116 | 174 | | |
117 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
118 | 191 | | |
119 | | - | |
| 192 | + | |
120 | 193 | | |
121 | 194 | | |
| 195 | + | |
122 | 196 | | |
123 | 197 | | |
124 | 198 | | |
| |||
133 | 207 | | |
134 | 208 | | |
135 | 209 | | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
| 210 | + | |
151 | 211 | | |
152 | | - | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
153 | 217 | | |
154 | 218 | | |
155 | 219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
0 commit comments