Skip to content

Commit fe1bf3b

Browse files
committed
refactor: add defensive type checks and improve null handling
1 parent 9a512d5 commit fe1bf3b

4 files changed

Lines changed: 9 additions & 6 deletions

File tree

crates/rari/src/rsc/rendering/core/js/component_eval_setup.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-use-before-define, no-var, vars-on-top */
2-
if (!globalThis.React) {
2+
if (!globalThis.React || typeof globalThis.React.createElement !== 'function') {
33
globalThis.React = {
44
createElement(type, props, ...children) {
55
const propsWithoutKey = props ? { ...props } : {}
@@ -29,7 +29,7 @@ if (typeof _jsxs === 'undefined')
2929

3030
if (typeof globalThis.jsx === 'undefined') {
3131
globalThis.jsx = function (type, props, key) {
32-
if (!globalThis.React)
32+
if (!globalThis.React || typeof globalThis.React.createElement !== 'function')
3333
return null
3434

3535
if (key !== undefined)
@@ -41,7 +41,7 @@ if (typeof globalThis.jsx === 'undefined') {
4141

4242
if (typeof globalThis.jsxs === 'undefined') {
4343
globalThis.jsxs = function (type, props, key) {
44-
if (!globalThis.React)
44+
if (!globalThis.React || typeof globalThis.React.createElement !== 'function')
4545
return null
4646

4747
if (key !== undefined)

crates/rari/src/server/middleware/request_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl RequestContext {
158158

159159
if let Some(result) = guard.as_ref() {
160160
let mut cloned_result = result.clone()?;
161-
cloned_result.tags = Self::merge_and_sort_tags(cloned_result.tags, tags.clone());
161+
cloned_result.tags = Self::merge_and_sort_tags(cloned_result.tags, tags);
162162

163163
{
164164
let mut cache = self.fetch_cache.lock();

packages/rari/src/router/navigation-error-handler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ export function createNavigationError(
134134
return handleTimeoutError(error, url)
135135

136136
if (error instanceof Error && 'status' in error) {
137-
const status = (error as any).status as number
137+
const status = (error as any).status
138+
if (typeof status !== 'number')
139+
return handleUnknownError(error, url)
140+
138141
return handleHttpError(error, status, url)
139142
}
140143

packages/rari/src/runtime/shared/get-client-component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async function ensureComponentLoaded(componentInfo: LazyComponentInfo, exportNam
6464
}
6565

6666
function triggerComponentLoad(componentInfo: LazyComponentInfo): Promise<any> {
67-
if (!componentInfo.loader || componentInfo.loading || componentInfo.component || componentInfo.loadPromise)
67+
if (!componentInfo.loader || componentInfo.loading || componentInfo.component != null || componentInfo.loadPromise)
6868
return Promise.resolve(null)
6969

7070
return executeLoader(componentInfo)

0 commit comments

Comments
 (0)