react-on-rails
Version:
react-on-rails JavaScript for react_on_rails Ruby gem
37 lines • 2.37 kB
JavaScript
/// <reference types="react/experimental" />
const throwRailsContextMissingEntries = (missingEntries) => {
throw new Error(`Rails context does not have server side ${missingEntries}.\n\n` +
'This is either a configuration issue or a bug:\n' +
'1. Ensure you are using a compatible version of react_on_rails_pro\n' +
'2. Ensure server components support is enabled:\n' +
' ReactOnRailsPro.configuration.enable_rsc_support = true\n\n' +
'If the above are correct, please report at https://github.com/shakacode/react_on_rails/issues');
};
export const assertRailsContextWithServerComponentMetadata = (context) => {
if (!context ||
!('reactClientManifestFileName' in context) ||
!('reactServerClientManifestFileName' in context)) {
throwRailsContextMissingEntries('server side RSC payload parameters, reactClientManifestFileName, and reactServerClientManifestFileName');
}
};
export const assertRailsContextWithServerStreamingCapabilities = (context) => {
assertRailsContextWithServerComponentMetadata(context);
// Verify the capabilities are callable, not merely present, so a misconfigured context fails here
// with the intended diagnostic instead of crashing later at a call site.
//
// `recordRSCDiagnostic` is intentionally NOT required here. It is an additive field (#3475); an
// external consumer constructing this context against an older Pro version may not supply it.
// Hard-throwing on its absence would be a compat regression for those consumers even though their
// type-check passes (the field is optional). Callers degrade gracefully when it is missing, so the
// assertion only guards the two pre-existing required capabilities.
// Cast to a Partial of the target type (rather than Record<string, unknown>) so the known
// capability keys stay typed while we runtime-check that each is actually a function.
const capabilities = context;
if (typeof capabilities.getRSCPayloadStream !== 'function' ||
typeof capabilities.addPostSSRHook !== 'function') {
throwRailsContextMissingEntries('getRSCPayloadStream and addPostSSRHook functions');
}
};
// Note: Global type declaration for ReactOnRails is in context.ts
// to avoid circular dependencies with ReactOnRailsInternal
//# sourceMappingURL=index.js.map