Bird
0
0

Identify the bug in this Remix loader for multi-tenant data fetching:

medium📝 Debug Q14 of 15
Remix - Advanced Patterns
Identify the bug in this Remix loader for multi-tenant data fetching:
export async function loader({ request }) {
  const url = new URL(request.url);
  const tenant = url.pathname.split('/')[2];
  if (!tenant) throw new Error('Tenant missing');
  return { tenant };
}
ALoader must not return an object
BTenant index should be 1, not 2
CError should be returned, not thrown
DMissing await keyword before new URL()
Step-by-Step Solution
Solution:
  1. Step 1: Analyze pathname splitting

    Pathname split by '/' results in ['', tenant, ...]. Tenant is at index 1, not 2.
  2. Step 2: Understand error condition

    If tenant is at index 2, it will often be undefined, causing error even when tenant exists.
  3. Final Answer:

    Tenant index should be 1, not 2 -> Option B
  4. Quick Check:

    Tenant = pathname.split('/')[1] [OK]
Quick Trick: Tenant is always at index 1 after splitting pathname [OK]
Common Mistakes:
MISTAKES
  • Using wrong index for tenant extraction
  • Confusing async usage with URL constructor
  • Throwing error instead of handling gracefully

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Remix Quizzes