Skip to content

Commit 1e519ff

Browse files
committed
refactor: add defensive checks and improve component resolution
1 parent d93a3d1 commit 1e519ff

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ if (typeof globalThis.jsxs === 'undefined')
4747
globalThis.jsxs = createJsxDelegate(globalThis['~react']?.jsxRuntime?.jsxs, undefined)
4848

4949
if (typeof globalThis.LoadingSpinner === 'undefined') {
50-
if (typeof document !== 'undefined' && !document.getElementById('spinner-keyframes')) {
50+
if (
51+
typeof document !== 'undefined'
52+
&& typeof document.getElementById === 'function'
53+
&& !document.getElementById('spinner-keyframes')
54+
) {
5155
const head = document.head || document.getElementsByTagName('head')[0]
5256
if (head) {
5357
const style = document.createElement('style')

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,19 @@ function resolveByName(
178178
clientComponents: Record<string, ComponentInfo>,
179179
clientComponentNames: Record<string, string>,
180180
): any {
181-
const componentId = clientComponentNames[id]
181+
const hashIndex = id.indexOf('#')
182+
const baseId = hashIndex === -1 ? id : id.slice(0, hashIndex)
183+
const exportName = hashIndex === -1 ? undefined : id.slice(hashIndex + 1)
184+
185+
const componentId = clientComponentNames[baseId]
182186
if (!componentId || !clientComponents[componentId])
183187
return null
184188

185189
const componentInfo = clientComponents[componentId] as LazyComponentInfo
190+
const component = getComponentFromInfo(componentInfo, exportName)
186191

187-
if (componentInfo.component != null)
188-
return componentInfo.component
192+
if (component !== null && component !== undefined)
193+
return component
189194

190195
tryLoadComponent(componentInfo)
191196
return null
@@ -241,11 +246,11 @@ export async function getClientComponentAsync(id: string): Promise<any> {
241246
}
242247
}
243248

244-
const componentId = clientComponentNames[id]
249+
const componentId = clientComponentNames[baseId]
245250
if (componentId) {
246251
componentInfo = clientComponents[componentId] as LazyComponentInfo
247252
if (componentInfo)
248-
return await ensureComponentLoaded(componentInfo)
253+
return await ensureComponentLoaded(componentInfo, exportName)
249254
}
250255

251256
return null

0 commit comments

Comments
 (0)