Skip to content

Commit

Permalink
feat(define-remix-app): expose a flag that signifies whether a dynami…
Browse files Browse the repository at this point in the history
…c page has the capability to provide its static routes (#1214)
  • Loading branch information
nadav-ab authored Oct 14, 2024
1 parent 8bb1f09 commit 63a4ee1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
6 changes: 6 additions & 0 deletions packages/app-core/src/define-app-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ export interface RouteInfo<T = unknown> {
editablePoints?: EditablePointOfInterest[];
}>;

/**
* signifies that a dynamic page has the capability to provide its static routes
*/
hasGetStaticRoutes?: boolean;


/**
* a list of export names of the page that should be editable
* if the page is a function, the UI will edit its return value
Expand Down
14 changes: 6 additions & 8 deletions packages/define-remix-app/src/define-remix-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export default function defineRemixApp({ appPath, routingPattern = 'file' }: IDe
routeId: filePathToRouteId(appDir, pageModule),
exportNames: varNames.size ? ['loader', 'meta', 'default'] : ['meta', 'default'],
},
hasGetStaticRoutes: false,
path: wantedPath,
pathString: requestedURI,
parentLayouts,
Expand All @@ -209,9 +210,9 @@ export default function defineRemixApp({ appPath, routingPattern = 'file' }: IDe
[manifest, importModule, setUri, onCaughtError, callServerMethod],
);

useEffect(()=>{
return clearLoadedModules
}, [])
useEffect(() => {
return clearLoadedModules;
}, []);
useEffect(() => {
navigate(uri.startsWith('/') ? uri : `/${uri}`);
}, [uri, navigate]);
Expand Down Expand Up @@ -272,11 +273,8 @@ export default function defineRemixApp({ appPath, routingPattern = 'file' }: IDe
}
return results as string[];
},
async hasGetStaticRoutes({fsApi}, forRouteAtFilePath) {
const {
exportNames,
stop,
} = fsApi.watchFileExports(forRouteAtFilePath, () => {});
async hasGetStaticRoutes({ fsApi }, forRouteAtFilePath) {
const { exportNames, stop } = fsApi.watchFileExports(forRouteAtFilePath, () => {});
const results = await exportNames;
const hasGetStaticRoutes = results.includes('getStaticRoutes');
stop();
Expand Down
2 changes: 2 additions & 0 deletions packages/define-remix-app/src/remix-app-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const aRoute = (
parentLayouts: extraData.parentLayouts,
pathString: filePathToReadableUri(pageModule.slice(routeDirPath.length + 1), pathApi) || '',
extraData,
hasGetStaticRoutes: extraData.exportNames.includes('getStaticRoutes'),
});
export const anErrorRoute = (
routeDirPath: string,
Expand All @@ -104,6 +105,7 @@ export const anErrorRoute = (
parentLayouts: extraData.parentLayouts,
pathString: filePathToReadableUri(pageModule.slice(routeDirPath.length + 1), pathApi) || '',
extraData,
hasGetStaticRoutes: extraData.exportNames.includes('getStaticRoutes'),
});
export function filePathToURLParts(filePathInRouteDir: string, path: PathApi): string[] {
const dirStructure = filePathInRouteDir.split(path.sep);
Expand Down
6 changes: 6 additions & 0 deletions packages/define-remix-app/test/define-remix.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,7 @@ const anyRoute = ({
path = [],
parentLayouts = [],
exportNames = ['default'],
hasGetStaticRoutes = false,
}: {
routeId: string;
pageModule: string;
Expand All @@ -1181,11 +1182,13 @@ const anyRoute = ({
path?: RouteInfo['path'];
parentLayouts?: RouteExtraInfo['parentLayouts'];
exportNames?: string[];
hasGetStaticRoutes?: boolean;
}): RouteInfo<RouteExtraInfo> => {
return {
path,
pathString,
pageModule,
hasGetStaticRoutes,
pageExportName,
extraData: {
parentLayouts,
Expand All @@ -1203,6 +1206,7 @@ const aRoute = ({
parentLayouts = [],
includeRootLayout = true,
exportNames,
hasGetStaticRoutes = false,
}: {
routeId: string;
pageModule: string;
Expand All @@ -1211,6 +1215,7 @@ const aRoute = ({
parentLayouts?: RouteExtraInfo['parentLayouts'];
includeRootLayout?: boolean;
exportNames?: string[];
hasGetStaticRoutes?: boolean;
}): RouteInfo<RouteExtraInfo> => {
const expectedParentLayouts = includeRootLayout ? [rootLayout, root, ...parentLayouts] : [root, ...parentLayouts];
return anyRoute({
Expand All @@ -1220,6 +1225,7 @@ const aRoute = ({
path,
parentLayouts: expectedParentLayouts,
exportNames,
hasGetStaticRoutes,
});
};

Expand Down

0 comments on commit 63a4ee1

Please sign in to comment.