0
0
Remixframework~20 mins

Multi-tenant applications in Remix - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Multi-tenant Remix Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does Remix handle tenant-specific data loading?

Consider a Remix loader function that fetches data based on the tenant ID from the URL params. What will the loader return if the tenant ID is missing?

Remix
import { json } from '@remix-run/node';

export async function loader({ params }) {
  const tenantId = params.tenantId;
  if (!tenantId) {
    return new Response('Tenant ID missing', { status: 400 });
  }
  const data = await fetchTenantData(tenantId);
  return json(data);
}
AIt returns an empty JSON object {}.
BIt throws a runtime error because tenantId is undefined.
CIt returns a 400 response with message 'Tenant ID missing'.
DIt returns data for a default tenant.
Attempts:
2 left
💡 Hint

Check the condition that handles missing tenantId in the loader.

state_output
intermediate
2:00remaining
Tenant context propagation in Remix components

Given a Remix app that uses a React context to store tenant info, what will be the value of tenantId inside a child component if the context provider is missing?

Remix
import React from 'react';

const TenantContext = React.createContext(null);

function ChildComponent() {
  const tenantId = React.useContext(TenantContext);
  return <div>{tenantId ?? 'No tenant'}</div>;
}
AThe component renders 'No tenant'.
BThe component throws an error because context is undefined.
CThe component renders 'null'.
DThe component renders an empty string.
Attempts:
2 left
💡 Hint

What is the default value of the context?

📝 Syntax
advanced
2:00remaining
Correct syntax for tenant-aware route in Remix

Which route file name correctly defines a dynamic tenant segment in Remix?

Aroutes/$tenantId/index.tsx
Broutes/:tenantId/index.tsx
Croutes/tenantId/index.tsx
Droutes/[tenantId]/index.tsx
Attempts:
2 left
💡 Hint

Remix uses a specific syntax for dynamic route segments.

🔧 Debug
advanced
2:00remaining
Why does tenant data not update on route change?

A Remix app fetches tenant data in a loader using params.tenantId. When navigating between tenants, the UI does not update with new tenant data. What is the likely cause?

Remix
import { json } from '@remix-run/node';
import { useLoaderData } from '@remix-run/react';

export async function loader({ params }) {
  const tenantId = params.tenantId;
  return json(await fetchTenantData(tenantId));
}

export default function TenantPage() {
  const data = useLoaderData();
  return <div>{data.name}</div>;
}
AfetchTenantData caches data and returns stale results.
BThe route path is not dynamic, so loader is not re-run on tenantId change.
CuseLoaderData is used incorrectly inside the component.
Dparams.tenantId is undefined because of a typo.
Attempts:
2 left
💡 Hint

Check if the route file name matches the dynamic segment.

🧠 Conceptual
expert
3:00remaining
Best practice for tenant isolation in Remix loaders

In a multi-tenant Remix app, what is the best way to ensure tenant data isolation in loaders?

AUse a single loader for all tenants and switch data based on user session.
BFetch all tenants' data once and filter in the component based on tenantId.
CStore tenant data globally in a React context and share across loaders.
DValidate tenantId from params and fetch data only for that tenant inside each loader.
Attempts:
2 left
💡 Hint

Think about security and data separation at the data fetching level.