Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"remark-gfm": "4.0.1",
"remark-parse": "^11.0.0",
"sharp": "0.35.5",
"tm-grammars": "1.32.22",
"unified": "^11.0.5",
"unist-util-visit": "^5.2.0",
"zod": "catalog:"
Expand Down
47 changes: 47 additions & 0 deletions apps/web/src/utils/shiki-ruby.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import c from '@shikijs/langs/c'
import css from '@shikijs/langs/css'
import graphql from '@shikijs/langs/graphql'
import haml from '@shikijs/langs/haml'
import html from '@shikijs/langs/html'
import javascript from '@shikijs/langs/javascript'
import lua from '@shikijs/langs/lua'
import shellscript from '@shikijs/langs/shellscript'
import sql from '@shikijs/langs/sql'
import xml from '@shikijs/langs/xml'
import yaml from '@shikijs/langs/yaml'
import type { LanguageRegistration } from '@shikijs/types'
import ruby from 'tm-grammars/grammars/ruby.json?raw'

// Shiki's Ruby entry also bundles C++ for heredocs. Load the grammar without it.
const language: LanguageRegistration = {
...(JSON.parse(ruby) as LanguageRegistration),
aliases: ['rb'],
embeddedLangs: [
'html',
'haml',
'xml',
'sql',
'graphql',
'css',
'c',
'javascript',
'shellscript',
'lua',
'yaml',
],
}

export default [
...html,
...haml,
...xml,
...sql,
...graphql,
...css,
...c,
...javascript,
...shellscript,
...lua,
...yaml,
language,
]
44 changes: 18 additions & 26 deletions apps/web/src/utils/shiki.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {
createSingletonShorthands,
} from '@shikijs/core'
import { createJavaScriptRegexEngine } from '@shikijs/engine-javascript'
import oneDarkProTheme from '@shikijs/themes/one-dark-pro'
import oneLightTheme from '@shikijs/themes/one-light'
/* Generate by @shikijs/codegen */
import type {
DynamicImportLanguageRegistration,
Expand All @@ -22,8 +20,6 @@ type BundledLanguage =
| 'angular-ts'
| 'astro'
| 'c'
| 'cpp'
| 'c++'
| 'csharp'
| 'c#'
| 'cs'
Expand Down Expand Up @@ -136,7 +132,6 @@ export const SHIKI_BUNDLED_LANGUAGE_GROUPS = [
{ id: 'angular-ts', name: 'Angular TypeScript' },
{ id: 'astro', name: 'Astro' },
{ id: 'c', name: 'C' },
{ id: 'cpp', name: 'C++', aliases: ['c++'] },
{ id: 'csharp', name: 'C#', aliases: ['c#', 'cs'] },
{ id: 'css', name: 'CSS' },
{ id: 'csv', name: 'CSV' },
Expand Down Expand Up @@ -229,22 +224,11 @@ function withCodeBlockBoldTokens(theme: ThemeRegistration, name: string) {
}) satisfies ThemeRegistration
}

const codeBlockShikiTheme = withCodeBlockBoldTokens(
oneDarkProTheme,
CODE_BLOCK_SHIKI_THEME
)
const codeBlockShikiLightTheme = withCodeBlockBoldTokens(
oneLightTheme,
CODE_BLOCK_SHIKI_LIGHT_THEME
)

const bundledLanguages = {
'angular-html': () => import('@shikijs/langs/angular-html'),
'angular-ts': () => import('@shikijs/langs/angular-ts'),
astro: () => import('@shikijs/langs/astro'),
c: () => import('@shikijs/langs/c'),
cpp: () => import('@shikijs/langs/cpp'),
'c++': () => import('@shikijs/langs/cpp'),
csharp: () => import('@shikijs/langs/csharp'),
'c#': () => import('@shikijs/langs/csharp'),
cs: () => import('@shikijs/langs/csharp'),
Expand Down Expand Up @@ -292,8 +276,8 @@ const bundledLanguages = {
prisma: () => import('@shikijs/langs/prisma'),
python: () => import('@shikijs/langs/python'),
py: () => import('@shikijs/langs/python'),
ruby: () => import('@shikijs/langs/ruby'),
rb: () => import('@shikijs/langs/ruby'),
ruby: () => import('#/utils/shiki-ruby'),
rb: () => import('#/utils/shiki-ruby'),
rust: () => import('@shikijs/langs/rust'),
rs: () => import('@shikijs/langs/rust'),
sass: () => import('@shikijs/langs/sass'),
Expand Down Expand Up @@ -325,14 +309,22 @@ const bundledThemes = {
'one-light': () => import('@shikijs/themes/one-light'),
'github-light': () => import('@shikijs/themes/github-light'),
'github-dark': () => import('@shikijs/themes/github-dark'),
[CODE_BLOCK_SHIKI_THEME]: () =>
Promise.resolve({
default: codeBlockShikiTheme,
}),
[CODE_BLOCK_SHIKI_LIGHT_THEME]: () =>
Promise.resolve({
default: codeBlockShikiLightTheme,
}),
[CODE_BLOCK_SHIKI_THEME]: async () => {
return {
default: withCodeBlockBoldTokens(
(await import('@shikijs/themes/one-dark-pro')).default,
CODE_BLOCK_SHIKI_THEME
),
}
},
[CODE_BLOCK_SHIKI_LIGHT_THEME]: async () => {
return {
default: withCodeBlockBoldTokens(
(await import('@shikijs/themes/one-light')).default,
CODE_BLOCK_SHIKI_LIGHT_THEME
),
}
},
} as Record<BundledTheme, DynamicImportThemeRegistration>

function getFontStyleHtmlStyle(token: ThemedToken) {
Expand Down
45 changes: 45 additions & 0 deletions apps/web/tests/public-content-prepare.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,51 @@ describe('public Markdown preparation', () => {
expect(result.projectsBySlug).toEqual({})
})

it.each(['cpp', 'c++'])(
'keeps %s code readable without syntax highlighting',
async (language) => {
const code = 'std::cout << "Hello";'
const result = await prepareContent({
slug: 'source',
content: `\`\`\`${language}\n${code}\n\`\`\``,
})
expect(result.codeBlocks[0]).toEqual({ code, language })
}
)

it.each(['ruby', 'rb'] as const)(
'highlights %s and embedded HTML without loading C++',
async (language) => {
const highlighter = await shiki.createHighlighter({
themes: [shiki.CODE_BLOCK_SHIKI_THEME],
langs: [language],
})
try {
const code = 'def greet\n puts <<~HTML\n <b>Hello</b>\n HTML\nend'
const { tokens } = highlighter.codeToTokens(code, {
lang: language,
theme: shiki.CODE_BLOCK_SHIKI_THEME,
tokenizeTimeLimit: 0,
})
expect(
tokens
.map((line) => line.map((token) => token.content).join(''))
.join('\n')
).toBe(code)
expect(
new Set(tokens[0].map((token) => token.color)).size
).toBeGreaterThan(1)
expect(
new Set(tokens[2].map((token) => token.color)).size
).toBeGreaterThan(1)
expect(highlighter.getLoadedLanguages()).not.toContain('cpp')
expect(highlighter.getLoadedLanguages()).not.toContain('c++')
} finally {
highlighter.dispose()
}
}
)

it.each(['powershell', 'ps1'] as const)(
'loads %s on demand for editor and public highlighting',
async (language) => {
Expand Down
30 changes: 30 additions & 0 deletions apps/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,36 @@ const config = defineConfig({
resolve: { tsconfigPaths: true },
server: { port: 3010 },
ssr: { external: ['@vercel/og', 'sharp'] },
environments: {
client: {
build: {
rolldownOptions: {
output: {
codeSplitting: {
groups: [
{
name: 'react',
test: /node_modules[\\/](?:react|react-dom|scheduler)[\\/]/,
},
{
name: 'editor',
test: /node_modules[\\/](?:@blocknote|@tiptap|prosemirror-[^\\/]+)[\\/]/,
entriesAware: true,
maxSize: 500_000,
},
{
name: 'shiki-languages',
test: /node_modules[\\/]@shikijs[\\/]langs[\\/]/,
entriesAware: true,
maxSize: 500_000,
},
],
},
},
},
},
},
},
optimizeDeps: {
include: ['@tanstack/react-form-start'],
},
Expand Down
3 changes: 3 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions packages/api/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { LoggerContext } from '@orpc/evlog'

import { auth } from '@altstack/auth/server'

export async function createORPCContext({ headers }: { headers: Headers }) {
const [{ auth }, { db }] = await Promise.all([
import('@altstack/auth/server'),
import('@altstack/db'),
])
const { db } = await import('@altstack/db')

const session = await auth.api.getSession({ headers })

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React Doctor · react-doctor/server-sequential-independent-await (warning)

This awaited initializer does not read the previous result. If the operations are independent asynchronous work, they may overlap; await syntax alone does not establish a speedup.

Fix → Consider Promise.all([...]) only for independent asynchronous work. Shared queues or synchronous work may not benefit. Preserve resource limits, transaction ordering, and failure/cancellation semantics.

Docs


Expand Down
Loading