react_on_rails 17.2.0.rc.0 → 17.2.0.rc.1
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/generators/react_on_rails/rsc_setup/client_references.rb +100 -30
- data/lib/react_on_rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 69798d53f8e79c799ad30c0910568deb5ff1f7e8308840960e72ae4dc59a112e
|
|
4
|
+
data.tar.gz: 8fe2437d15ab95544e9d6165429789b72bc42721333c1fcd90283ad274e4afec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e67061bd03e02f6457e40d8d6a686e5ae02c315e594f4843c8b79892aab0c3fe402bb5690f3430dcff07a3d6b4ab1f8deb4085f3824b7c97ee59601cd3d46f4a
|
|
7
|
+
data.tar.gz: 97fa89ad907a46fe4ba3b6ae1eaab139015bd7708a5413b39867960ec89932b5a109e47e86d4d4aa27d7e4d0299cd19d63a0c3d95992c4b29eaa50c827a675a2
|
data/Gemfile.lock
CHANGED
|
@@ -43,8 +43,10 @@ module ReactOnRails
|
|
|
43
43
|
// (which re-runs the hook). Running bin/shakapacker directly after changing server
|
|
44
44
|
// components is covered by the best-effort staleness warning below.
|
|
45
45
|
//
|
|
46
|
-
// The resolution cascade below
|
|
47
|
-
//
|
|
46
|
+
// The resolution cascade below — including the react-on-rails-pro client-component
|
|
47
|
+
// registrations appended to every branch's result (issue #5079) — is mirrored, branch
|
|
48
|
+
// for branch, by the Pro dummy's hand-written rscManifestClientReferences.js and pinned
|
|
49
|
+
// on both sides by contract tests.
|
|
48
50
|
const rscClientReferences = (() => {
|
|
49
51
|
// Required inside the IIFE rather than at the top of the file because the module-scope
|
|
50
52
|
// bindings 'resolve' (from 'path') and 'config' (from 'shakapacker') are already
|
|
@@ -168,40 +170,73 @@ module ReactOnRails
|
|
|
168
170
|
);
|
|
169
171
|
};
|
|
170
172
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
173
|
+
const resolveDiscoveredClientReferences = () => {
|
|
174
|
+
if (configuredRefsJson) {
|
|
175
|
+
const resolvedRefsJson = resolve(configuredRefsJson);
|
|
176
|
+
if (!existsSync(resolvedRefsJson)) {
|
|
177
|
+
throw new Error(
|
|
178
|
+
`RSC_MANIFEST_CLIENT_REFERENCES_JSON is set but the file does not exist: ${resolvedRefsJson}`,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
warnIfManifestStale(resolvedRefsJson);
|
|
182
|
+
return readManifestReferences(resolvedRefsJson);
|
|
177
183
|
}
|
|
178
|
-
warnIfManifestStale(resolvedRefsJson);
|
|
179
|
-
return readManifestReferences(resolvedRefsJson);
|
|
180
|
-
}
|
|
181
184
|
|
|
182
|
-
|
|
183
|
-
return [fallbackRscClientReferences];
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (existsSync(defaultRefsJson)) {
|
|
187
|
-
warnIfManifestStale(defaultRefsJson);
|
|
188
|
-
return readManifestReferences(defaultRefsJson);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (existsSync(serverComponentRegistrationEntry)) {
|
|
192
|
-
if (!rscConfigSupportsDiscovery()) {
|
|
193
|
-
console.warn(
|
|
194
|
-
`[react_on_rails] Missing ${defaultRefsJson}, but this app's RSC webpack config ` +
|
|
195
|
-
'or precompile hook does not support manifest discovery yet; falling back to broad client ' +
|
|
196
|
-
'reference scan. Re-run rails g react_on_rails:rsc to update generated configs.',
|
|
197
|
-
);
|
|
185
|
+
if (process.env.RSC_REFERENCE_DISCOVERY_BUILD === 'true' || process.env.RSC_BUNDLE_ONLY === 'true') {
|
|
198
186
|
return [fallbackRscClientReferences];
|
|
199
187
|
}
|
|
200
188
|
|
|
201
|
-
|
|
202
|
-
|
|
189
|
+
if (existsSync(defaultRefsJson)) {
|
|
190
|
+
warnIfManifestStale(defaultRefsJson);
|
|
191
|
+
return readManifestReferences(defaultRefsJson);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (existsSync(serverComponentRegistrationEntry)) {
|
|
195
|
+
if (!rscConfigSupportsDiscovery()) {
|
|
196
|
+
console.warn(
|
|
197
|
+
`[react_on_rails] Missing ${defaultRefsJson}, but this app's RSC webpack config ` +
|
|
198
|
+
'or precompile hook does not support manifest discovery yet; falling back to broad client ' +
|
|
199
|
+
'reference scan. Re-run rails g react_on_rails:rsc to update generated configs.',
|
|
200
|
+
);
|
|
201
|
+
return [fallbackRscClientReferences];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
throw new Error(`Missing ${defaultRefsJson}. Run bin/shakapacker-precompile-hook before bin/shakapacker.`);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return [fallbackRscClientReferences];
|
|
208
|
+
};
|
|
203
209
|
|
|
204
|
-
|
|
210
|
+
// react-on-rails-pro ships its own 'use client' components (RSCRoute, RSCProvider, and
|
|
211
|
+
// the default RSC provider registration). Both the discovery build and the fallback
|
|
212
|
+
// directory scan only cover app source — node_modules is never scanned — so these can
|
|
213
|
+
// never be discovered and, without explicit registration, never reach
|
|
214
|
+
// react-client-manifest.json. Server components rendering them (e.g. a nested
|
|
215
|
+
// <RSCRoute> for section-level refetching) then fail the render-time manifest lookup
|
|
216
|
+
// even when the RSC bundle compiles (issue #5079). require.resolve returns the
|
|
217
|
+
// absolute realpath, which matches the module resource webpack records
|
|
218
|
+
// (resolve.symlinks defaults to true), so the manifest keys line up with the file URLs
|
|
219
|
+
// the RSC bundle's client references carry even when react-on-rails-pro is installed
|
|
220
|
+
// through a symlink (pnpm, workspaces). A function (invoked in the return below, after
|
|
221
|
+
// the discovered references resolve) so both this resolver and its Pro dummy mirror
|
|
222
|
+
// surface the same first error when both steps fail.
|
|
223
|
+
const reactOnRailsProClientReferences = () =>
|
|
224
|
+
[
|
|
225
|
+
'react-on-rails-pro/RSCRoute',
|
|
226
|
+
'react-on-rails-pro/RSCProvider',
|
|
227
|
+
'react-on-rails-pro/registerDefaultRSCProvider/client',
|
|
228
|
+
].map((subpath) => {
|
|
229
|
+
try {
|
|
230
|
+
return require.resolve(subpath);
|
|
231
|
+
} catch (err) {
|
|
232
|
+
throw new Error(
|
|
233
|
+
`Failed to resolve the react-on-rails-pro client component "${subpath}" for RSC ` +
|
|
234
|
+
`client-reference registration: ${err.message}`,
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
return [...new Set([...resolveDiscoveredClientReferences(), ...reactOnRailsProClientReferences()])];
|
|
205
240
|
})();
|
|
206
241
|
JS
|
|
207
242
|
end
|
|
@@ -277,6 +312,10 @@ module ReactOnRails
|
|
|
277
312
|
|
|
278
313
|
content = read_current_rsc_config(config_path, fallback: content)
|
|
279
314
|
end
|
|
315
|
+
# A previously generated IIFE (no react-on-rails-pro registrations — issue #5079) also
|
|
316
|
+
# counts as generated below; warn so the user registers the components manually.
|
|
317
|
+
warn_outdated_rsc_client_references_helper(config_path) if
|
|
318
|
+
outdated_generated_rsc_client_references_defined?(content)
|
|
280
319
|
return :scoped if generated_rsc_client_references_defined?(content)
|
|
281
320
|
|
|
282
321
|
warn_unscoped_rsc_client_references_helper(config_path)
|
|
@@ -312,6 +351,12 @@ module ReactOnRails
|
|
|
312
351
|
content = normalized_content
|
|
313
352
|
end
|
|
314
353
|
|
|
354
|
+
# A resolver emitted by a previous generator version (no react-on-rails-pro
|
|
355
|
+
# client-component registrations — issue #5079) is deliberately not rewritten; warn
|
|
356
|
+
# before the scoped-references short-circuit below treats it as already current.
|
|
357
|
+
warn_outdated_rsc_client_references_helper(config_path) if
|
|
358
|
+
outdated_generated_rsc_client_references_defined?(content)
|
|
359
|
+
|
|
315
360
|
return unless rsc_plugin_sections_safe_to_rewrite?(config_path, content, is_server:)
|
|
316
361
|
|
|
317
362
|
return if rsc_plugin_uses_scoped_client_references?(content, is_server:)
|
|
@@ -1405,6 +1450,31 @@ module ReactOnRails
|
|
|
1405
1450
|
write_existing_rsc_config(config_path, updated_content, action: :rewrite)
|
|
1406
1451
|
end
|
|
1407
1452
|
|
|
1453
|
+
# True when the file carries a manifest-backed generated resolver IIFE that does not
|
|
1454
|
+
# register the react-on-rails-pro client components (issue #5079) — either the resolver a
|
|
1455
|
+
# previous generator version emitted, or a user customization of one. The generator never
|
|
1456
|
+
# rewrites such a resolver; it warns with manual registration instructions instead.
|
|
1457
|
+
def outdated_generated_rsc_client_references_defined?(content)
|
|
1458
|
+
return false unless generated_rsc_client_references_defined?(content)
|
|
1459
|
+
|
|
1460
|
+
iife_body = generated_rsc_client_references_iife_body(content)
|
|
1461
|
+
return false unless iife_body
|
|
1462
|
+
|
|
1463
|
+
!js_code_matches?(iife_body, /\breactOnRailsProClientReferences\b/)
|
|
1464
|
+
end
|
|
1465
|
+
|
|
1466
|
+
def warn_outdated_rsc_client_references_helper(config_path)
|
|
1467
|
+
GeneratorMessages.add_warning(
|
|
1468
|
+
"#{config_path} contains a rscClientReferences resolver from a previous generator " \
|
|
1469
|
+
"version: it does not register the react-on-rails-pro package's own client components " \
|
|
1470
|
+
"(RSCRoute, RSCProvider, registerDefaultRSCProvider/client — issue #5079). The file was " \
|
|
1471
|
+
"left unchanged. Add require.resolve entries for those components to your " \
|
|
1472
|
+
"clientReferences (see the RSC setup docs at " \
|
|
1473
|
+
"https://reactonrails.com/docs/pro/react-server-components/create-without-ssr), or " \
|
|
1474
|
+
"remove the generated resolver block and re-run this generator to emit the current one."
|
|
1475
|
+
)
|
|
1476
|
+
end
|
|
1477
|
+
|
|
1408
1478
|
def read_current_rsc_config(config_path, fallback:)
|
|
1409
1479
|
return fallback if options[:pretend] || options[:skip]
|
|
1410
1480
|
|