Unverified Commit 2225e589 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

[dev-overlay] minify css (#76370)

### Why?

Our internal comments in the css literal templates, are being shipped to
the client along with the dev overlay, which is a bad practice.


https://github.com/vercel/next.js/blob/7f5a1d39e8a94b0b424ef9538be9dd2802e6ccb6/packages/next/src/client/components/react-dev-overlay/ui/components/errors/error-overlay-bottom-stack/index.tsx#L104-L107

### How?

Added minifying css util that includes removing comments.

| Before | After |
|--------|--------|
| ![CleanShot 2025-02-22 at 17 56
33@2x](https://github.com/user-attachments/assets/7af3d4a2-2ca2-4702-991d-beef84587837)
| ![CleanShot 2025-02-22 at 17 56
18@2x](https://github.com/user-attachments/assets/8fa9a3b7-b475-448f-a4ff-63f517f8df90)
|

- Renamed `noop` util to `css`.
- Added minifying in `css` util.
- Added unit test for `css` util.
- Removed unnecessary `css` util usage as it's only required for the
entry point (where it injects to `<style>` tag).
- Updated README (will follow up to improve).

Note: This loses the benefit of VS Code extension
`styled-components.vscode-styled-components`, so dropping it from
recommendations.

| Before | After |
|--------|--------|
| ![CleanShot 2025-02-22 at 17 24
52@2x](https://github.com/user-attachments/assets/4b73f1b9-42a8-44f0-9083-7117be973bed)
| ![CleanShot 2025-02-22 at 17 24
58@2x](https://github.com/user-attachments/assets/1b5e9448-0802-4abc-8bb5-01bacdb2d2c5)
|

Closes NDX-750
Closes NDX-839
parent 9b0edbb7
...@@ -23,9 +23,6 @@ ...@@ -23,9 +23,6 @@
"ms-vscode.vscode-js-profile-flame", "ms-vscode.vscode-js-profile-flame",
// MDX Authoring // MDX Authoring
"unifiedjs.vscode-mdx", "unifiedjs.vscode-mdx"
// CSS Authoring (mainly Dev Overlay)
"styled-components.vscode-styled-components"
] ]
} }
...@@ -3,3 +3,8 @@ TODO ...@@ -3,3 +3,8 @@ TODO
### Folder Structure ### Folder Structure
- `ui` - This should be isolated from the rest of the codebase to make it easier to be excluded from compiliation and be bundled. - `ui` - This should be isolated from the rest of the codebase to make it easier to be excluded from compiliation and be bundled.
### Styling
- The entrypoint needs to use `css` util that minifies styles.
- Entrypoint is which are using `<style>` tag to inject styles.
import { noop as css } from '../utils/noop-template' import { css } from '../utils/css'
import { useInsertionEffect } from 'react' import { useInsertionEffect } from 'react'
export const FontStyles = () => { export const FontStyles = () => {
......
...@@ -5,7 +5,6 @@ import { HotlinkedText } from '../hot-linked-text' ...@@ -5,7 +5,6 @@ import { HotlinkedText } from '../hot-linked-text'
import { ExternalIcon } from '../../icons/external' import { ExternalIcon } from '../../icons/external'
import { getFrameSource } from '../../../utils/stack-frame' import { getFrameSource } from '../../../utils/stack-frame'
import { useOpenInEditor } from '../../utils/use-open-in-editor' import { useOpenInEditor } from '../../utils/use-open-in-editor'
import { noop as css } from '../../../utils/noop-template'
export const CallStackFrame: React.FC<{ export const CallStackFrame: React.FC<{
frame: OriginalStackFrame frame: OriginalStackFrame
...@@ -69,7 +68,7 @@ export const CallStackFrame: React.FC<{ ...@@ -69,7 +68,7 @@ export const CallStackFrame: React.FC<{
) )
} }
export const CALL_STACK_FRAME_STYLES = css` export const CALL_STACK_FRAME_STYLES = `
[data-nextjs-call-stack-frame-ignored] { [data-nextjs-call-stack-frame-ignored] {
padding: var(--size-1_5) var(--size-2); padding: var(--size-1_5) var(--size-2);
margin-bottom: var(--size-1); margin-bottom: var(--size-1);
......
...@@ -7,7 +7,6 @@ import { useMemo } from 'react' ...@@ -7,7 +7,6 @@ import { useMemo } from 'react'
import { HotlinkedText } from '../hot-linked-text' import { HotlinkedText } from '../hot-linked-text'
import { getFrameSource } from '../../../utils/stack-frame' import { getFrameSource } from '../../../utils/stack-frame'
import { useOpenInEditor } from '../../utils/use-open-in-editor' import { useOpenInEditor } from '../../utils/use-open-in-editor'
import { noop as css } from '../../../utils/noop-template'
import { ExternalIcon } from '../../icons/external' import { ExternalIcon } from '../../icons/external'
import { FileIcon } from '../../icons/file' import { FileIcon } from '../../icons/file'
...@@ -112,7 +111,7 @@ export function CodeFrame({ stackFrame, codeFrame }: CodeFrameProps) { ...@@ -112,7 +111,7 @@ export function CodeFrame({ stackFrame, codeFrame }: CodeFrameProps) {
) )
} }
export const CODE_FRAME_STYLES = css` export const CODE_FRAME_STYLES = `
[data-nextjs-codeframe] { [data-nextjs-codeframe] {
background-color: var(--color-background-200); background-color: var(--color-background-200);
overflow: hidden; overflow: hidden;
......
import * as React from 'react' import * as React from 'react'
import { noop as css } from '../../../utils/noop-template'
import { cx } from '../../utils/cx' import { cx } from '../../utils/cx'
function useCopyLegacy(content: string) { function useCopyLegacy(content: string) {
...@@ -246,7 +245,7 @@ function CopySuccessIcon() { ...@@ -246,7 +245,7 @@ function CopySuccessIcon() {
) )
} }
export const COPY_BUTTON_STYLES = css` export const COPY_BUTTON_STYLES = `
.nextjs-data-copy-button { .nextjs-data-copy-button {
color: inherit; color: inherit;
} }
......
import { noop as css } from '../../../utils/noop-template' const styles = `
const styles = css`
[data-nextjs-dialog-root] { [data-nextjs-dialog-root] {
--next-dialog-radius: var(--rounded-xl); --next-dialog-radius: var(--rounded-xl);
--next-dialog-footer-height: 48px; --next-dialog-footer-height: 48px;
......
import type { OriginalStackFrame } from '../../../../utils/stack-frame' import type { OriginalStackFrame } from '../../../../utils/stack-frame'
import { useMemo, useState, useRef } from 'react' import { useMemo, useState, useRef } from 'react'
import { CallStackFrame } from '../../call-stack-frame/call-stack-frame' import { CallStackFrame } from '../../call-stack-frame/call-stack-frame'
import { noop as css } from '../../../../utils/noop-template'
interface CallStackProps { interface CallStackProps {
frames: OriginalStackFrame[] frames: OriginalStackFrame[]
...@@ -119,7 +118,7 @@ function ChevronUpDown() { ...@@ -119,7 +118,7 @@ function ChevronUpDown() {
) )
} }
export const CALL_STACK_STYLES = css` export const CALL_STACK_STYLES = `
.error-overlay-call-stack-container { .error-overlay-call-stack-container {
position: relative; position: relative;
margin-top: var(--size-2); margin-top: var(--size-2);
......
...@@ -7,7 +7,6 @@ import { NextLogo } from './next-logo' ...@@ -7,7 +7,6 @@ import { NextLogo } from './next-logo'
import { useIsDevBuilding } from '../../../../../../dev/dev-build-indicator/internal/initialize' import { useIsDevBuilding } from '../../../../../../dev/dev-build-indicator/internal/initialize'
import { useIsDevRendering } from '../../../../utils/dev-indicator/dev-render-indicator' import { useIsDevRendering } from '../../../../utils/dev-indicator/dev-render-indicator'
import { useDelayedRender } from '../../../hooks/use-delayed-render' import { useDelayedRender } from '../../../hooks/use-delayed-render'
import { noop as css } from '../../../../utils/noop-template'
import { TurbopackInfo } from './dev-tools-info/turbopack-info' import { TurbopackInfo } from './dev-tools-info/turbopack-info'
import { RouteInfo } from './dev-tools-info/route-info' import { RouteInfo } from './dev-tools-info/route-info'
import { StopIcon } from '../../../icons/stop-icon' import { StopIcon } from '../../../icons/stop-icon'
...@@ -538,7 +537,7 @@ function useClickOutside( ...@@ -538,7 +537,7 @@ function useClickOutside(
////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////
export const DEV_TOOLS_INDICATOR_STYLES = css` export const DEV_TOOLS_INDICATOR_STYLES = `
.dev-tools-indicator-menu { .dev-tools-indicator-menu {
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
display: flex; display: flex;
......
import { noop as css } from '../../../../../utils/noop-template'
export function DevToolsInfo({ export function DevToolsInfo({
title, title,
children, children,
...@@ -43,7 +41,7 @@ export function DevToolsInfo({ ...@@ -43,7 +41,7 @@ export function DevToolsInfo({
) )
} }
export const DEV_TOOLS_INFO_STYLES = css` export const DEV_TOOLS_INFO_STYLES = `
[data-info-popover] { [data-info-popover] {
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
display: flex; display: flex;
......
import { DevToolsInfo } from './dev-tools-info' import { DevToolsInfo } from './dev-tools-info'
import { noop as css } from '../../../../../utils/noop-template'
function StaticRouteContent() { function StaticRouteContent() {
return ( return (
...@@ -105,7 +104,7 @@ export function RouteInfo({ ...@@ -105,7 +104,7 @@ export function RouteInfo({
) )
} }
export const DEV_TOOLS_INFO_ROUTE_INFO_STYLES = css` export const DEV_TOOLS_INFO_ROUTE_INFO_STYLES = `
.dev-tools-info-link { .dev-tools-info-link {
} }
` `
import { DevToolsInfo } from './dev-tools-info' import { DevToolsInfo } from './dev-tools-info'
import { CopyButton } from '../../../copy-button' import { CopyButton } from '../../../copy-button'
import { noop as css } from '../../../../../utils/noop-template'
export function TurbopackInfo({ export function TurbopackInfo({
isOpen, isOpen,
...@@ -111,7 +110,7 @@ export function TurbopackInfo({ ...@@ -111,7 +110,7 @@ export function TurbopackInfo({
) )
} }
export const DEV_TOOLS_INFO_TURBOPACK_INFO_STYLES = css` export const DEV_TOOLS_INFO_TURBOPACK_INFO_STYLES = `
.dev-tools-info-code { .dev-tools-info-code {
background: var(--color-gray-400); background: var(--color-gray-400);
color: var(--color-gray-1000); color: var(--color-gray-1000);
......
import { forwardRef, useEffect, useRef, useState } from 'react' import { forwardRef, useEffect, useRef, useState } from 'react'
import { noop as css } from '../../../../utils/noop-template' import { css } from '../../../../utils/css'
import mergeRefs from '../../../utils/merge-refs' import mergeRefs from '../../../utils/merge-refs'
import { useMinimumLoadingTimeMultiple } from './use-minimum-loading-time-multiple' import { useMinimumLoadingTimeMultiple } from './use-minimum-loading-time-multiple'
......
import { noop as css } from '../../../../utils/noop-template'
import { DialogBody } from '../../dialog' import { DialogBody } from '../../dialog'
type ErrorOverlayDialogBodyProps = { type ErrorOverlayDialogBodyProps = {
...@@ -14,4 +13,4 @@ export function ErrorOverlayDialogBody({ ...@@ -14,4 +13,4 @@ export function ErrorOverlayDialogBody({
) )
} }
export const DIALOG_BODY_STYLES = css`` export const DIALOG_BODY_STYLES = ``
import { Dialog } from '../../dialog/dialog' import { Dialog } from '../../dialog/dialog'
import { noop as css } from '../../../../utils/noop-template'
type ErrorOverlayDialogProps = { type ErrorOverlayDialogProps = {
children?: React.ReactNode children?: React.ReactNode
...@@ -26,7 +25,7 @@ export function ErrorOverlayDialog({ ...@@ -26,7 +25,7 @@ export function ErrorOverlayDialog({
) )
} }
export const DIALOG_STYLES = css` export const DIALOG_STYLES = `
.error-overlay-dialog { .error-overlay-dialog {
overflow-y: auto; overflow-y: auto;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
......
import { DialogHeader } from '../../dialog/dialog-header' import { DialogHeader } from '../../dialog/dialog-header'
import { noop as css } from '../../../../utils/noop-template'
type ErrorOverlayDialogHeaderProps = { type ErrorOverlayDialogHeaderProps = {
children?: React.ReactNode children?: React.ReactNode
...@@ -15,7 +14,7 @@ export function ErrorOverlayDialogHeader({ ...@@ -15,7 +14,7 @@ export function ErrorOverlayDialogHeader({
) )
} }
export const DIALOG_HEADER_STYLES = css` export const DIALOG_HEADER_STYLES = `
.nextjs-container-errors-header { .nextjs-container-errors-header {
position: relative; position: relative;
} }
......
import { noop as css } from '../../../../utils/noop-template'
export function EnvironmentNameLabel({ export function EnvironmentNameLabel({
environmentName, environmentName,
}: { }: {
...@@ -8,7 +6,7 @@ export function EnvironmentNameLabel({ ...@@ -8,7 +6,7 @@ export function EnvironmentNameLabel({
return <span data-nextjs-environment-name-label>{environmentName}</span> return <span data-nextjs-environment-name-label>{environmentName}</span>
} }
export const ENVIRONMENT_NAME_LABEL_STYLES = css` export const ENVIRONMENT_NAME_LABEL_STYLES = `
[data-nextjs-environment-name-label] { [data-nextjs-environment-name-label] {
padding: var(--size-0_5) var(--size-1_5); padding: var(--size-0_5) var(--size-1_5);
margin: 0; margin: 0;
......
import { useState, useRef, useLayoutEffect } from 'react' import { useState, useRef, useLayoutEffect } from 'react'
import { noop as css } from '../../../../utils/noop-template'
export type ErrorMessageType = React.ReactNode export type ErrorMessageType = React.ReactNode
...@@ -44,7 +43,7 @@ export function ErrorMessage({ errorMessage }: ErrorMessageProps) { ...@@ -44,7 +43,7 @@ export function ErrorMessage({ errorMessage }: ErrorMessageProps) {
) )
} }
export const styles = css` export const styles = `
.nextjs__container_errors_wrapper { .nextjs__container_errors_wrapper {
position: relative; position: relative;
} }
......
import { noop as css } from '../../../../utils/noop-template'
export function ErrorOverlayBottomStack({ export function ErrorOverlayBottomStack({
count, count,
activeIdx, activeIdx,
...@@ -35,7 +33,7 @@ export function ErrorOverlayBottomStack({ ...@@ -35,7 +33,7 @@ export function ErrorOverlayBottomStack({
) )
} }
export const styles = css` export const styles = `
.layer { .layer {
width: 100%; width: 100%;
height: var(--stack-layer-height); height: var(--stack-layer-height);
......
import { useState, useCallback } from 'react' import { useState, useCallback } from 'react'
import { ThumbsUp } from '../../../../icons/thumbs/thumbs-up' import { ThumbsUp } from '../../../../icons/thumbs/thumbs-up'
import { ThumbsDown } from '../../../../icons/thumbs/thumbs-down' import { ThumbsDown } from '../../../../icons/thumbs/thumbs-down'
import { noop as css } from '../../../../../utils/noop-template'
import { cx } from '../../../../utils/cx' import { cx } from '../../../../utils/cx'
interface ErrorFeedbackProps { interface ErrorFeedbackProps {
...@@ -83,7 +82,7 @@ export function ErrorFeedback({ errorCode, className }: ErrorFeedbackProps) { ...@@ -83,7 +82,7 @@ export function ErrorFeedback({ errorCode, className }: ErrorFeedbackProps) {
) )
} }
export const styles = css` export const styles = `
.error-feedback { .error-feedback {
display: flex; display: flex;
align-items: center; align-items: center;
......
import { ErrorFeedback } from './error-feedback/error-feedback' import { ErrorFeedback } from './error-feedback/error-feedback'
import { styles as feedbackStyles } from './error-feedback/error-feedback' import { styles as feedbackStyles } from './error-feedback/error-feedback'
import { noop as css } from '../../../../utils/noop-template'
export type ErrorOverlayFooterProps = { export type ErrorOverlayFooterProps = {
errorCode: string | undefined errorCode: string | undefined
...@@ -23,7 +22,7 @@ export function ErrorOverlayFooter({ ...@@ -23,7 +22,7 @@ export function ErrorOverlayFooter({
) )
} }
export const styles = css` export const styles = `
.error-overlay-footer { .error-overlay-footer {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
......
...@@ -8,7 +8,6 @@ import { ...@@ -8,7 +8,6 @@ import {
styles as toolbarStyles, styles as toolbarStyles,
} from '../error-overlay-toolbar/error-overlay-toolbar' } from '../error-overlay-toolbar/error-overlay-toolbar'
import { ErrorOverlayFooter } from '../error-overlay-footer/error-overlay-footer' import { ErrorOverlayFooter } from '../error-overlay-footer/error-overlay-footer'
import { noop as css } from '../../../../utils/noop-template'
import { import {
ErrorMessage, ErrorMessage,
styles as errorMessageStyles, styles as errorMessageStyles,
...@@ -138,7 +137,7 @@ export function ErrorOverlayLayout({ ...@@ -138,7 +137,7 @@ export function ErrorOverlayLayout({
) )
} }
export const styles = css` export const styles = `
${OVERLAY_STYLES} ${OVERLAY_STYLES}
${DIALOG_STYLES} ${DIALOG_STYLES}
${DIALOG_HEADER_STYLES} ${DIALOG_HEADER_STYLES}
......
...@@ -2,7 +2,6 @@ import type { VersionInfo } from '../../../../../../../server/dev/parse-version- ...@@ -2,7 +2,6 @@ import type { VersionInfo } from '../../../../../../../server/dev/parse-version-
import { ErrorOverlayPagination } from '../error-overlay-pagination/error-overlay-pagination' import { ErrorOverlayPagination } from '../error-overlay-pagination/error-overlay-pagination'
import { VersionStalenessInfo } from '../../version-staleness-info/version-staleness-info' import { VersionStalenessInfo } from '../../version-staleness-info/version-staleness-info'
import { noop as css } from '../../../../utils/noop-template'
import type { ReadyRuntimeError } from '../../../../utils/get-error-by-type' import type { ReadyRuntimeError } from '../../../../utils/get-error-by-type'
type ErrorOverlayNavProps = { type ErrorOverlayNavProps = {
...@@ -42,7 +41,7 @@ export function ErrorOverlayNav({ ...@@ -42,7 +41,7 @@ export function ErrorOverlayNav({
) )
} }
export const styles = css` export const styles = `
[data-nextjs-error-overlay-nav] { [data-nextjs-error-overlay-nav] {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
......
...@@ -5,7 +5,6 @@ import { ...@@ -5,7 +5,6 @@ import {
useRef, useRef,
useState, useState,
} from 'react' } from 'react'
import { noop as css } from '../../../../utils/noop-template'
import { LeftArrow } from '../../../icons/left-arrow' import { LeftArrow } from '../../../icons/left-arrow'
import { RightArrow } from '../../../icons/right-arrow' import { RightArrow } from '../../../icons/right-arrow'
import type { ReadyRuntimeError } from '../../../../utils/get-error-by-type' import type { ReadyRuntimeError } from '../../../../utils/get-error-by-type'
...@@ -152,7 +151,7 @@ export function ErrorOverlayPagination({ ...@@ -152,7 +151,7 @@ export function ErrorOverlayPagination({
) )
} }
export const styles = css` export const styles = `
.error-overlay-pagination { .error-overlay-pagination {
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
display: flex; display: flex;
......
import type { DebugInfo } from '../../../../types' import type { DebugInfo } from '../../../../types'
import { NodejsInspectorButton } from './nodejs-inspector-button' import { NodejsInspectorButton } from './nodejs-inspector-button'
import { noop as css } from '../../../../utils/noop-template'
import { CopyStackTraceButton } from './copy-stack-trace-button' import { CopyStackTraceButton } from './copy-stack-trace-button'
import { DocsLinkButton } from './docs-link-button' import { DocsLinkButton } from './docs-link-button'
...@@ -24,7 +23,7 @@ export function ErrorOverlayToolbar({ ...@@ -24,7 +23,7 @@ export function ErrorOverlayToolbar({
) )
} }
export const styles = css` export const styles = `
.error-overlay-toolbar { .error-overlay-toolbar {
display: flex; display: flex;
gap: var(--size-1_5); gap: var(--size-1_5);
......
import { noop as css } from '../../../../utils/noop-template'
export type ErrorType = export type ErrorType =
| 'Build Error' | 'Build Error'
| 'Runtime Error' | 'Runtime Error'
...@@ -22,7 +20,7 @@ export function ErrorTypeLabel({ errorType }: ErrorTypeLabelProps) { ...@@ -22,7 +20,7 @@ export function ErrorTypeLabel({ errorType }: ErrorTypeLabelProps) {
) )
} }
export const styles = css` export const styles = `
.nextjs__container_errors_label { .nextjs__container_errors_label {
padding: var(--size-0_5) var(--size-1_5); padding: var(--size-0_5) var(--size-1_5);
margin: 0; margin: 0;
......
import { noop as css } from '../../../../utils/noop-template'
import { Overlay, type OverlayProps } from '../../overlay/overlay' import { Overlay, type OverlayProps } from '../../overlay/overlay'
export function ErrorOverlayOverlay({ children, ...props }: OverlayProps) { export function ErrorOverlayOverlay({ children, ...props }: OverlayProps) {
return <Overlay {...props}>{children}</Overlay> return <Overlay {...props}>{children}</Overlay>
} }
export const OVERLAY_STYLES = css` export const OVERLAY_STYLES = `
[data-nextjs-dialog-overlay] { [data-nextjs-dialog-overlay] {
padding: initial; padding: initial;
top: 10vh; top: 10vh;
......
import { noop as css } from '../../../utils/noop-template' const styles = `
const styles = css`
[data-nextjs-dialog-overlay] { [data-nextjs-dialog-overlay] {
position: fixed; position: fixed;
top: 0; top: 0;
......
import { useOpenInEditor } from '../../utils/use-open-in-editor' import { useOpenInEditor } from '../../utils/use-open-in-editor'
import { noop as css } from '../../../utils/noop-template'
type EditorLinkProps = { type EditorLinkProps = {
file: string file: string
...@@ -44,7 +43,7 @@ export function EditorLink({ file, location }: EditorLinkProps) { ...@@ -44,7 +43,7 @@ export function EditorLink({ file, location }: EditorLinkProps) {
) )
} }
export const EDITOR_LINK_STYLES = css` export const EDITOR_LINK_STYLES = `
[data-with-open-in-editor-link] svg { [data-with-open-in-editor-link] svg {
width: auto; width: auto;
height: var(--size-font-small); height: var(--size-font-small);
......
...@@ -3,7 +3,6 @@ import * as React from 'react' ...@@ -3,7 +3,6 @@ import * as React from 'react'
import { HotlinkedText } from '../hot-linked-text' import { HotlinkedText } from '../hot-linked-text'
import { EditorLink } from './editor-link' import { EditorLink } from './editor-link'
import { ExternalIcon } from '../../icons/external' import { ExternalIcon } from '../../icons/external'
import { noop as css } from '../../../utils/noop-template'
import { getFrameSource } from '../../../utils/stack-frame' import { getFrameSource } from '../../../utils/stack-frame'
import { useOpenInEditor } from '../../utils/use-open-in-editor' import { useOpenInEditor } from '../../utils/use-open-in-editor'
import { FileIcon } from '../../icons/file' import { FileIcon } from '../../icons/file'
...@@ -144,7 +143,7 @@ export const Terminal: React.FC<TerminalProps> = function Terminal({ ...@@ -144,7 +143,7 @@ export const Terminal: React.FC<TerminalProps> = function Terminal({
) )
} }
export const TERMINAL_STYLES = css` export const TERMINAL_STYLES = `
[data-nextjs-terminal]::selection, [data-nextjs-terminal]::selection,
[data-nextjs-terminal] *::selection { [data-nextjs-terminal] *::selection {
background-color: var(--color-ansi-selection); background-color: var(--color-ansi-selection);
......
import { noop as css } from '../../../utils/noop-template' const styles = `
const styles = css`
.nextjs-toast { .nextjs-toast {
position: fixed; position: fixed;
bottom: var(--size-gap-double); bottom: var(--size-gap-double);
......
import type { VersionInfo } from '../../../../../../server/dev/parse-version-info' import type { VersionInfo } from '../../../../../../server/dev/parse-version-info'
import { cx } from '../../utils/cx' import { cx } from '../../utils/cx'
import { noop as css } from '../../../utils/noop-template'
export function VersionStalenessInfo({ export function VersionStalenessInfo({
versionInfo, versionInfo,
...@@ -88,7 +87,7 @@ export function getStaleness({ installed, staleness, expected }: VersionInfo) { ...@@ -88,7 +87,7 @@ export function getStaleness({ installed, staleness, expected }: VersionInfo) {
return { text, indicatorClass, title } return { text, indicatorClass, title }
} }
export const styles = css` export const styles = `
.nextjs-container-build-error-version-status { .nextjs-container-build-error-version-status {
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
display: flex; display: flex;
......
import React, { useCallback, useMemo } from 'react' import React, { useCallback, useMemo } from 'react'
import stripAnsi from 'next/dist/compiled/strip-ansi' import stripAnsi from 'next/dist/compiled/strip-ansi'
import { Terminal } from '../components/terminal' import { Terminal } from '../components/terminal'
import { noop as css } from '../../utils/noop-template'
import { ErrorOverlayLayout } from '../components/errors/error-overlay-layout/error-overlay-layout' import { ErrorOverlayLayout } from '../components/errors/error-overlay-layout/error-overlay-layout'
import type { ErrorBaseProps } from '../components/errors/error-overlay/error-overlay' import type { ErrorBaseProps } from '../components/errors/error-overlay/error-overlay'
...@@ -48,4 +47,4 @@ export const BuildError: React.FC<BuildErrorProps> = function BuildError({ ...@@ -48,4 +47,4 @@ export const BuildError: React.FC<BuildErrorProps> = function BuildError({
) )
} }
export const styles = css`` export const styles = ``
import { useState, useMemo, useEffect, useRef, Suspense } from 'react' import { useState, useMemo, useEffect, useRef, Suspense } from 'react'
import type { DebugInfo } from '../../types' import type { DebugInfo } from '../../types'
import { Overlay } from '../components/overlay' import { Overlay } from '../components/overlay'
import { noop as css } from '../../utils/noop-template'
import { RuntimeError } from './runtime-error' import { RuntimeError } from './runtime-error'
import { getErrorSource } from '../../../../../shared/lib/error-source' import { getErrorSource } from '../../../../../shared/lib/error-source'
import { HotlinkedText } from '../components/hot-linked-text' import { HotlinkedText } from '../components/hot-linked-text'
...@@ -208,7 +207,7 @@ export function Errors({ ...@@ -208,7 +207,7 @@ export function Errors({
) )
} }
export const styles = css` export const styles = `
.nextjs-error-with-static { .nextjs-error-with-static {
bottom: calc(var(--size-gap-double) * 4.5); bottom: calc(var(--size-gap-double) * 4.5);
} }
......
import { noop as css } from '../../../utils/noop-template'
export { PseudoHtmlDiff } from '../../components/hydration-diff/diff-view' export { PseudoHtmlDiff } from '../../components/hydration-diff/diff-view'
export const PSEUDO_HTML_DIFF_STYLES = css` export const PSEUDO_HTML_DIFF_STYLES = `
[data-nextjs-container-errors-pseudo-html] { [data-nextjs-container-errors-pseudo-html] {
padding: var(--size-2) 0; padding: var(--size-2) 0;
margin: var(--size-2) 0; margin: var(--size-2) 0;
......
import { useMemo } from 'react' import { useMemo } from 'react'
import { CodeFrame } from '../../components/code-frame/code-frame' import { CodeFrame } from '../../components/code-frame/code-frame'
import { CallStack } from '../../components/errors/call-stack/call-stack' import { CallStack } from '../../components/errors/call-stack/call-stack'
import { noop as css } from '../../../utils/noop-template'
import { PSEUDO_HTML_DIFF_STYLES } from './component-stack-pseudo-html' import { PSEUDO_HTML_DIFF_STYLES } from './component-stack-pseudo-html'
import { import {
useFrames, useFrames,
...@@ -43,6 +42,6 @@ export function RuntimeError({ error, dialogResizerRef }: RuntimeErrorProps) { ...@@ -43,6 +42,6 @@ export function RuntimeError({ error, dialogResizerRef }: RuntimeErrorProps) {
) )
} }
export const styles = css` export const styles = `
${PSEUDO_HTML_DIFF_STYLES} ${PSEUDO_HTML_DIFF_STYLES}
` `
import * as React from 'react' import * as React from 'react'
import { noop as css } from '../../utils/noop-template' import { css } from '../../utils/css'
export function Base() { export function Base() {
return ( return (
......
import { noop as css } from '../../utils/noop-template' import { css } from '../../utils/css'
// TODO: Replace the existing colors in Base.tsx. // TODO: Replace the existing colors in Base.tsx.
export function Colors() { export function Colors() {
......
...@@ -14,7 +14,7 @@ import { styles as containerRuntimeErrorStyles } from '../container/runtime-erro ...@@ -14,7 +14,7 @@ import { styles as containerRuntimeErrorStyles } from '../container/runtime-erro
import { COPY_BUTTON_STYLES } from '../components/copy-button' import { COPY_BUTTON_STYLES } from '../components/copy-button'
import { CALL_STACK_FRAME_STYLES } from '../components/call-stack-frame/call-stack-frame' import { CALL_STACK_FRAME_STYLES } from '../components/call-stack-frame/call-stack-frame'
import { DEV_TOOLS_INDICATOR_STYLES } from '../components/errors/dev-tools-indicator/dev-tools-indicator' import { DEV_TOOLS_INDICATOR_STYLES } from '../components/errors/dev-tools-indicator/dev-tools-indicator'
import { noop as css } from '../../utils/noop-template' import { css } from '../../utils/css'
import { EDITOR_LINK_STYLES } from '../components/terminal/editor-link' import { EDITOR_LINK_STYLES } from '../components/terminal/editor-link'
import { ENVIRONMENT_NAME_LABEL_STYLES } from '../components/errors/environment-name-label/environment-name-label' import { ENVIRONMENT_NAME_LABEL_STYLES } from '../components/errors/environment-name-label/environment-name-label'
import { DEV_TOOLS_INFO_STYLES } from '../components/errors/dev-tools-indicator/dev-tools-info/dev-tools-info' import { DEV_TOOLS_INFO_STYLES } from '../components/errors/dev-tools-indicator/dev-tools-info/dev-tools-info'
......
import * as React from 'react' import * as React from 'react'
import { noop as css } from '../../utils/noop-template' import { css } from '../../utils/css'
export function CssReset() { export function CssReset() {
return ( return (
......
import { css } from './css'
describe('css template literal tag', () => {
test('combines strings and interpolations correctly', () => {
const color = 'red'
const result = css`
color: ${color};
background: blue;
`
expect(result).toBe('color:red;background:blue;')
})
test('removes all whitespace', () => {
const result = css`
margin: 0;
padding: 10px;
`
expect(result).toBe('margin:0;padding:10px;')
})
test('removes CSS comments', () => {
const result = css`
color: blue; /* this is a comment */
/* multi-line
comment */
/** jsdoc */
margin: 10px;
`
expect(result).toBe('color:blue;margin:10px;')
})
test('handles multiple interpolations', () => {
const width = '100px'
const height = '200px'
const result = css`
width: ${width};
height: ${height};
color: blue; /* this is a comment */
/* multi-line
comment */
/** jsdoc */
`
expect(result).toBe('width:100px;height:200px;color:blue;')
})
test('handles empty strings', () => {
const result = css``
expect(result).toBe('')
})
test('handles CSS wildcard selector', () => {
const result = css`
* {
margin: 0;
padding: 0;
}
`
expect(result).toBe('*{margin:0;padding:0}')
})
})
export function noop( export function css(
strings: TemplateStringsArray, strings: TemplateStringsArray,
...keys: readonly string[] ...keys: readonly string[]
) { ): string {
const lastIndex = strings.length - 1 const lastIndex = strings.length - 1
return ( const str =
// Convert template literal into a single line string
strings.slice(0, lastIndex).reduce((p, s, i) => p + s + keys[i], '') + strings.slice(0, lastIndex).reduce((p, s, i) => p + s + keys[i], '') +
strings[lastIndex] strings[lastIndex]
return (
str
// Remove comments
.replace(/\/\*[\s\S]*?\*\//g, '')
// Remove whitespace, tabs, and newlines
.replace(/\s+/g, ' ')
// Remove spaces before and after semicolons, and spaces after commas
.replace(/\s*([:;,{}])\s*/g, '$1')
// Remove extra semicolons
.replace(/;+}/g, '}')
// Trim leading and trailing whitespaces
.trim()
) )
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment