Skip to content

fix: Add is404 flag for 404ed routes #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
603c1f1
feat : add import/no-default-export eslint rule.
Ta5r Apr 4, 2025
bd598d5
chore : updated files for no-default-exports.
Ta5r Apr 4, 2025
5e2df69
chore : add changeset.
Ta5r Apr 4, 2025
33c10fc
Merge branch 'develop' into feat/import-no-default-export
Ta5r Apr 4, 2025
0b88cc1
chore : reorder-import
Ta5r Apr 4, 2025
29025e1
temp : fix failing gh actions
Ta5r Apr 4, 2025
89eaa67
fix : export default for codegen config and baseConfig
Ta5r Apr 4, 2025
123a436
Merge branch 'develop' into feat/import-no-default-export
justlevine Apr 4, 2025
fd0f6da
Merge pull request #147 from Ta5r/feat/import-no-default-export
Ta5r Apr 8, 2025
76dcef2
feat: add connectedNode field to template query
Swanand01 Apr 9, 2025
5a80814
feat: add `is404` flag to parseQueryResult return values
Swanand01 Apr 9, 2025
6542789
chore: add changeset
Swanand01 Apr 9, 2025
5a13a33
chore: add is404 test
Swanand01 Apr 9, 2025
119c625
Merge branch 'develop' into fix/status-code-for-404ed-routes
Swanand01 Apr 9, 2025
0d8f1d5
feat: expose `is404` to the frontend
Swanand01 Apr 10, 2025
63c4f79
chore: use named import in next config
Swanand01 Apr 10, 2025
5ee8cca
Merge remote-tracking branch 'upstream/develop' into fix/status-code-…
Swanand01 Apr 10, 2025
8202409
feat: add 404 handling to current path middleware
Swanand01 Apr 10, 2025
74120c2
Merge branch 'develop' into fix/status-code-for-404ed-routes
justlevine Apr 11, 2025
5b3bc6b
refactor: remove custom header
Swanand01 Apr 11, 2025
e607e12
refactor: update is404 parsing
Swanand01 Apr 14, 2025
5088f62
fix: update tests
Swanand01 Apr 14, 2025
3193579
revert: current path middleware
Swanand01 Apr 15, 2025
a6bb2cd
feat: redirect to not-found
Swanand01 Apr 15, 2025
8d4a0ce
revert: connectedNode from query
Swanand01 Apr 15, 2025
680b91d
Merge branch 'develop' into fix/status-code-for-404ed-routes
Swanand01 Apr 15, 2025
9240dfe
revert: not-found.tsx
Swanand01 Apr 16, 2025
5ff9667
Merge branch 'fix/status-code-for-404ed-routes' of https://github.com…
Swanand01 Apr 16, 2025
73f7b8c
Merge branch 'develop' into fix/status-code-for-404ed-routes
Swanand01 Apr 16, 2025
02877c7
revert: passing is404 to `TeemplateRenderer` children
Swanand01 Apr 17, 2025
f9570ed
feat: add docs on handling 404 pages
Swanand01 Apr 17, 2025
200e7b0
chore: update changeset
Swanand01 Apr 17, 2025
9884e17
chore: sort query a to z
Swanand01 Apr 17, 2025
f01314f
chore: format
Swanand01 Apr 17, 2025
ef20325
chore: cleanup
justlevine Apr 17, 2025
74b88cd
docs: working example
justlevine Apr 17, 2025
c97d860
chore: format
justlevine Apr 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/some-laws-bet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@snapwp/codegen-config": patch
"@snapwp/e2e-tests": patch
"@snapwp/blocks": patch
"@snapwp/query": patch
"@snapwp/core": patch
"@snapwp/next": patch
---

chore: Enforce named exports and remove default exports.
5 changes: 5 additions & 0 deletions .changeset/tame-beans-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@snapwp/query": patch
---

fix: Add is404 flag for 404ed routes
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module.exports = {
// Import rules.
'import/default': 'error',
'import/named': 'error',
'import/no-default-export': 'error',

// Jest rules.
'jest/expect-expect': 'off',
Expand Down
8 changes: 4 additions & 4 deletions packages/blocks/src/block-manager/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import defaultBlockDefinitions from '@/blocks';
import Default from '@/blocks/default';
import flatListToHierarchical from '@/utils/flat-list-to-hierarchical';
import { blocks as defaultBlockDefinitions } from '@/blocks';
import { Default } from '@/blocks/default';
import { flatListToHierarchical } from '@/utils/flat-list-to-hierarchical';

import type { BlockData, BlockDefinitions, BlockTreeNode } from '@snapwp/types';

/**
* Singleton class that renders blocks using defined React components.
* Falls back to a default block if the type isn't found.
*/
export default class BlockManager {
export class BlockManager {
private static blockDefinitions = defaultBlockDefinitions;

/**
Expand Down
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-audio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { ReactNode } from 'react';
*
* @return The rendered block.
*/
const CoreAudio: CoreAudioType = ( {
export const CoreAudio: CoreAudioType = ( {
attributes,
renderedHtml,
}: CoreAudioProps ): ReactNode => {
Expand Down Expand Up @@ -56,5 +56,3 @@ const CoreAudio: CoreAudioType = ( {
</figure>
);
};

export default CoreAudio;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { ButtonHTMLAttributes, ReactNode } from 'react';
*
* @return The rendered block.
*/
const CoreButton: CoreButtonType = ( {
export const CoreButton: CoreButtonType = ( {
attributes,
}: CoreButtonProps ): ReactNode => {
const {
Expand Down Expand Up @@ -75,5 +75,3 @@ const CoreButton: CoreButtonType = ( {
</div>
);
};

export default CoreButton;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { ReactNode } from 'react';
*
* @return The rendered block.
*/
const CoreButtons: CoreButtonsType = ( {
export const CoreButtons: CoreButtonsType = ( {
attributes,
children,
}: CoreButtonsProps ): ReactNode => {
Expand All @@ -32,5 +32,3 @@ const CoreButtons: CoreButtonsType = ( {
</div>
);
};

export default CoreButtons;
6 changes: 3 additions & 3 deletions packages/blocks/src/blocks/core-code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import type { ReactNode } from 'react';
*
* @return The rendered block.
*/
const CoreCode: CoreCodeType = ( { attributes }: CoreCodeProps ): ReactNode => {
export const CoreCode: CoreCodeType = ( {
attributes,
}: CoreCodeProps ): ReactNode => {
const { style, cssClassName, content } = attributes || {};

const styleObject = getStylesFromAttributes( { style } );
Expand All @@ -25,5 +27,3 @@ const CoreCode: CoreCodeType = ( { attributes }: CoreCodeProps ): ReactNode => {
</pre>
);
};

export default CoreCode;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { CSSProperties, ReactNode } from 'react';
*
* @return The rendered block.
*/
const CoreColumn: CoreColumnType = ( {
export const CoreColumn: CoreColumnType = ( {
attributes,
children,
}: CoreColumnProps ): ReactNode => {
Expand All @@ -34,5 +34,3 @@ const CoreColumn: CoreColumnType = ( {
</div>
);
};

export default CoreColumn;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { ReactNode } from 'react';
*
* @return The rendered block.
*/
const CoreColumns: CoreColumnsType = ( {
export const CoreColumns: CoreColumnsType = ( {
attributes,
children,
}: CoreColumnsProps ): ReactNode => {
Expand All @@ -32,5 +32,3 @@ const CoreColumns: CoreColumnsType = ( {
</div>
);
};

export default CoreColumns;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-cover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const mediaPosition = (
*
* @return The rendered cover block or null if using featured image
*/
const CoreCover: CoreCoverType = ( {
export const CoreCover: CoreCoverType = ( {
attributes,
connectedMediaItem,
mediaDetails,
Expand Down Expand Up @@ -190,5 +190,3 @@ const CoreCover: CoreCoverType = ( {
</Tag>
);
};

export default CoreCover;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { ReactNode } from 'react';
*
* @return The rendered block.
*/
const CoreDetails: CoreDetailsType = ( {
export const CoreDetails: CoreDetailsType = ( {
attributes,
children,
renderedHtml,
Expand Down Expand Up @@ -47,5 +47,3 @@ const CoreDetails: CoreDetailsType = ( {
</details>
);
};

export default CoreDetails;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const FALLBACK_ARIA_LABEL = 'PDF embed';
*
* @return The rendered block.
*/
const CoreFile: CoreFileType = ( {
export const CoreFile: CoreFileType = ( {
attributes,
renderedHtml,
}: CoreFileProps ): ReactNode => {
Expand Down Expand Up @@ -90,5 +90,3 @@ const CoreFile: CoreFileType = ( {
</div>
);
};

export default CoreFile;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-freeform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { ReactNode } from 'react';
*
* @return The rendered block.
*/
const CoreFreeform: CoreFreeformType = ( {
export const CoreFreeform: CoreFreeformType = ( {
renderedHtml,
}: CoreFreeformProps ): ReactNode => {
// @todo `attribues.content` is not populated in GraphQL. Using `renderedHtml` for now.
Expand All @@ -23,5 +23,3 @@ const CoreFreeform: CoreFreeformType = ( {

return <Parse html={ renderedHtml } />;
};

export default CoreFreeform;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { ReactNode } from 'react';
*
* @return The rendered block.
*/
const CoreGallery: CoreGalleryType = ( {
export const CoreGallery: CoreGalleryType = ( {
attributes,
children,
renderedHtml,
Expand Down Expand Up @@ -50,5 +50,3 @@ const CoreGallery: CoreGalleryType = ( {
</figure>
);
};

export default CoreGallery;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const Tag = ( {
*
* @return The rendered block.
*/
const CoreGroup: CoreGroupType = ( {
export const CoreGroup: CoreGroupType = ( {
attributes,
renderedHtml,
children,
Expand Down Expand Up @@ -79,5 +79,3 @@ const CoreGroup: CoreGroupType = ( {
</Tag>
);
};

export default CoreGroup;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { JSX, ReactNode } from 'react';
*
* @return The rendered block.
*/
const CoreHeading: CoreHeadingType = ( {
export const CoreHeading: CoreHeadingType = ( {
attributes,
}: CoreHeadingProps ): ReactNode => {
const { style, cssClassName, content, level } = attributes || {};
Expand All @@ -34,5 +34,3 @@ const CoreHeading: CoreHeadingType = ( {
</HeadingTag>
);
};

export default CoreHeading;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { ReactNode } from 'react';
*
* @return The rendered block.
*/
const CoreHtml: CoreHtmlType = ( {
export const CoreHtml: CoreHtmlType = ( {
renderedHtml,
}: CoreHtmlProps ): ReactNode => {
// @todo use attributes.content instead of renderedHtml once it's available
Expand All @@ -20,5 +20,3 @@ const CoreHtml: CoreHtmlType = ( {

return <Parse html={ renderedHtml } />;
};

export default CoreHtml;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const Figure = ( {
*
* @return The rendered core image block or null if no URL is provided.
*/
const CoreImage: CoreImageType = ( {
export const CoreImage: CoreImageType = ( {
attributes,
connectedMediaItem,
mediaDetails,
Expand Down Expand Up @@ -340,5 +340,3 @@ const extractAriaAttributesForElement = (

return result;
};

export default CoreImage;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { ReactNode } from 'react';
*
* @return The rendered block.
*/
const CoreListItem: CoreListItemType = ( {
export const CoreListItem: CoreListItemType = ( {
attributes,
renderedHtml,
children,
Expand Down Expand Up @@ -49,5 +49,3 @@ const CoreListItem: CoreListItemType = ( {
</li>
);
};

export default CoreListItem;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { CSSProperties, ReactNode } from 'react';
*
* @return The rendered block.
*/
const CoreList: CoreListType = ( {
export const CoreList: CoreListType = ( {
attributes,
children,
}: CoreListProps ): ReactNode => {
Expand Down Expand Up @@ -40,5 +40,3 @@ const CoreList: CoreListType = ( {
</TagName>
);
};

export default CoreList;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-media-text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function imageFillStyles(
*
* @return Rendered component or null if no content
*/
const CoreMediaText: CoreMediaTextType = ( {
export const CoreMediaText: CoreMediaTextType = ( {
attributes = {},
children,
renderedHtml,
Expand Down Expand Up @@ -180,5 +180,3 @@ const CoreMediaText: CoreMediaTextType = ( {
</div>
);
};

export default CoreMediaText;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-paragraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { ReactNode } from 'react';
*
* @return The rendered block.
*/
const CoreParagraph: CoreParagraphType = ( {
export const CoreParagraph: CoreParagraphType = ( {
attributes,
}: CoreParagraphProps ): ReactNode => {
const {
Expand Down Expand Up @@ -60,5 +60,3 @@ const CoreParagraph: CoreParagraphType = ( {
</p>
);
};

export default CoreParagraph;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-pattern.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import type { ReactNode } from 'react';
*
* @return The rendered block.
*/
const CorePattern: CorePatternType = ( {
export const CorePattern: CorePatternType = ( {
children,
}: CorePatternProps ): ReactNode => {
// Patterns contain only children, so we just return them.
return <>{ children }</>;
};

export default CorePattern;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-post-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { ReactNode } from 'react';
*
* @return The rendered block.
*/
const CorePostContent: CorePostContentType = ( {
export const CorePostContent: CorePostContentType = ( {
renderedHtml,
children,
}: CorePostContentProps ): ReactNode => {
Expand All @@ -27,5 +27,3 @@ const CorePostContent: CorePostContentType = ( {
const classNames = cn( classNamesFromString );
return <div className={ classNames }>{ children }</div>;
};

export default CorePostContent;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-preformatted.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { ReactNode } from 'react';
*
* @return The rendered block.
*/
const CorePreformatted: CorePreformattedType = ( {
export const CorePreformatted: CorePreformattedType = ( {
attributes,
renderedHtml,
}: CorePreformattedProps ): ReactNode => {
Expand All @@ -45,5 +45,3 @@ const CorePreformatted: CorePreformattedType = ( {
</pre>
);
};

export default CorePreformatted;
4 changes: 1 addition & 3 deletions packages/blocks/src/blocks/core-pullquote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { ReactNode } from 'react';
*
* @return The rendered block.
*/
const CorePullquote: CorePullquoteType = ( {
export const CorePullquote: CorePullquoteType = ( {
attributes,
renderedHtml,
}: CorePullquoteProps ): ReactNode => {
Expand Down Expand Up @@ -57,5 +57,3 @@ const CorePullquote: CorePullquoteType = ( {
</figure>
);
};

export default CorePullquote;
Loading