Skip to content

Commit

Permalink
Added noSsr option to server renderer - and applied to task pages
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenwf committed Nov 26, 2024
1 parent 0b3c4ac commit 1bf3ce0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ export function serverRendererFor<TVariables = any, Data = any>(
getData?: (key: string, vars: TVariables, api: ApiClient, pathname: string) => Promise<Data>;
hooks?: AdditionalHooks[];
theme?: { name: string } & Partial<MadocTheme>;
noSsr?: boolean;
}
) {
(component as any).noSsr = config.noSsr;
(component as any).getKey = config.getKey;
(component as any).getData = config.getData;
(component as any).hooks = config.hooks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function createServerRenderer(
routeContext.project = match.params.slug ? match.params.slug : undefined;
}

if (route.component && route.component.getKey && route.component.getData) {
if (route.component && route.component.getKey && route.component.getData && route.component.noSsr !== true) {
requests.push(
prefetchCache.prefetchQuery(
route.component.getKey(match.params, queryString, path),
Expand Down Expand Up @@ -362,7 +362,7 @@ export function createServerRenderer(
: `
<script>document.body.classList.add('dev-loading');</script>
<style>
body > * {
body > * {
transition: opacity 200ms;
}
.dev-loading > * {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function createUniversalComponent<
Component: React.FC,
options: {
getKey?: GetKey;
noSsr?: boolean;
getData?: GetData;
hooks?: AdditionalHooks[];
}
Expand All @@ -26,5 +27,6 @@ export function createUniversalComponent<
ReturnComponent.getKey = options.getKey;
ReturnComponent.getData = options.getData;
ReturnComponent.hooks = options.hooks;
ReturnComponent.noSsr = options.noSsr;
return ReturnComponent;
}
8 changes: 7 additions & 1 deletion services/madoc-ts/src/frontend/site/pages/all-tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ export const AllTasks: UniversalComponent<AllTasksType> = createUniversalCompone
const user = useUser();
const isAdmin = user && user.scope && user.scope.indexOf('site.admin') !== -1;
const isReviewer = isAdmin || (user && user.scope && user.scope.indexOf('tasks.create') !== -1);
const { data: pages, fetchMore, canFetchMore, isFetchingMore } = useInfiniteData(AllTasks, undefined, {
const {
data: pages,
fetchMore,
canFetchMore,
isFetchingMore,
} = useInfiniteData(AllTasks, undefined, {
getFetchMore: lastPage => {
if (lastPage.pagination.totalPages === 0 || lastPage.pagination.totalPages === lastPage.pagination.page) {
return undefined;
Expand Down Expand Up @@ -172,6 +177,7 @@ export const AllTasks: UniversalComponent<AllTasksType> = createUniversalCompone
);
},
{
noSsr: true,
getKey: (params, { preview, ...query }) => {
return ['all-tasks', { query, projectSlug: params.slug }];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ function SingleReviewTableRow({
}

serverRendererFor(ReviewListingPage, {
noSsr: true,
getKey: (params, { preview, ...query }) => {
return ['all-review-tasks', { query, projectSlug: params.slug, page: query.page || 1 }];
},
Expand Down

0 comments on commit 1bf3ce0

Please sign in to comment.