Skip to content

Commit

Permalink
Refactor MenuItem components and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
RoelLeijser committed Dec 10, 2024
1 parent 8595ab2 commit 8fe34f8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
3 changes: 0 additions & 3 deletions browser/create-template/templates/nextjs-site/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ const nextConfig = {

return config;
},
experimental: {
turbo: {},
},
};

export default nextConfig;
18 changes: 6 additions & 12 deletions browser/create-template/templates/nextjs-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev --turbopack",
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
Expand All @@ -16,26 +16,20 @@
"clsx": "^2.1.1",
"gray-matter": "^4.0.3",
"modern-css-reset": "^1.4.0",
"next": "15.0.2",
"react": "19.0.0-rc-02c0e824-20241028",
"react-dom": "19.0.0-rc-02c0e824-20241028",
"next": "15.0.4",
"react": "19.0.0",
"react-dom": "19.0.0",
"remark": "^15.0.1",
"remark-html": "^16.0.1",
"zod": "^3.23.8"
},
"devDependencies": {
"@tomic/cli": "^0.40.0",
"@types/node": "^20",
"@types/react": "npm:types-react@19.0.0-rc.1",
"@types/react-dom": "npm:types-react-dom@19.0.0-rc.1",
"@types/react": "19.0.1",
"@types/react-dom": "19.0.1",
"eslint": "^9.13.0",
"eslint-config-next": "15.0.2",
"typescript": "^5"
},
"pnpm": {
"overrides": {
"@types/react": "npm:[email protected]",
"@types/react-dom": "npm:[email protected]"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const MenuItem = ({ subject }: { subject: string }) => {
const menuItem = useResource<MenuItem>(subject);
const { currentSubject } = useCurrentSubject();
const id = useId();
const anchorName = CSS.escape(`--menuItem-${id}`);
const anchorName = cssEscape(`--menuItem-${id}`);
const popover = useRef<HTMLDivElement>(null);
const button = useRef<HTMLButtonElement>(null);
const [submenuPosition, setSubmenuPosition] = useState({
Expand All @@ -22,7 +22,10 @@ const MenuItem = ({ subject }: { subject: string }) => {
const calcPopoverPosition = () => {
if (!button.current || !popover.current) return;

if (CSS.supports('anchor-name', '--something')) {
if (
typeof CSS !== 'undefined' &&
CSS.supports('anchor-name', '--something')
) {
return;
}

Expand Down Expand Up @@ -60,7 +63,6 @@ const MenuItem = ({ subject }: { subject: string }) => {
onClick={calcPopoverPosition}
ref={button}
style={{ '--anchor-name': anchorName } as React.CSSProperties}
suppressHydrationWarning
>
{menuItem.title}
</button>
Expand All @@ -78,7 +80,6 @@ const MenuItem = ({ subject }: { subject: string }) => {
'--anchor-name': anchorName,
} as React.CSSProperties
}
suppressHydrationWarning
>
<ul className={styles.ul}>
{menuItem.props.subItems?.map((subItem: string, index: number) => (
Expand All @@ -97,4 +98,11 @@ const MenuItem = ({ subject }: { subject: string }) => {
);
};

const cssEscape = (value: string) => {
if (typeof CSS !== 'undefined' && CSS.escape) {
return CSS.escape(value);
}
return value.replace(/([!"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~])/g, '\\$1');
};

export default MenuItem;
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const MenuItemLink = ({
href={href}
className={clsx(styles.link, { [styles.linkActive]: active })}
aria-current={active ? 'page' : 'false'}
suppressHydrationWarning
>
{resource.loading ? '' : page.title}
</Link>
Expand Down

0 comments on commit 8fe34f8

Please sign in to comment.