Skip to content

Condense frontend guidelines#881

Merged
michal-lightly merged 4 commits intomainfrom
michal-lig-9026-update-ai-instructions--4-condense-frontend
Apr 7, 2026
Merged

Condense frontend guidelines#881
michal-lightly merged 4 commits intomainfrom
michal-lig-9026-update-ai-instructions--4-condense-frontend

Conversation

@michal-lightly
Copy link
Copy Markdown
Contributor

@michal-lightly michal-lightly commented Apr 1, 2026

What has changed and why?

Condense the frontend guidelines. They were too verbose and repetitive.

How has it been tested?

N/A

Did you update CHANGELOG.md?

  • Yes
  • Not needed (internal change)

Summary by CodeRabbit

  • Documentation
    • Condensed frontend guidelines into a concise, directive-style checklist.
    • Streamlines guidance on state management, component sizing, hooks, and store-first patterns.
    • Clarifies Svelte 5 control-flow and event conventions and preferred derived/store usage.
    • Simplifies examples and pares back extensive testing, routing, and API/storybook prescriptions.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 1, 2026

📝 Walkthrough

Walkthrough

Condenses and rewrites ai_guidelines/frontend.md from a long best-practices document into a concise, directive-style frontend coding-standards checklist, streamlining guidance across Svelte state/reactivity, imports, TypeScript patterns, component sizing, hooks, testing, and build constraints.

Changes

Cohort / File(s) Summary
Frontend Guidelines Rewrite
ai_guidelines/frontend.md
Substantial rewrite: removes extensive section-by-section best-practices content and replaces it with concise directives covering Svelte 5 control-flow (use $props(), onclick/onchange, prefer $derived/derived() over $:, use $app/state not $app/stores, avoid passing $derived into hooks), prefer small hooks in src/lib/hooks (de-emphasize services), component size limits (~100 lines), absolute imports, TypeScript derived-type patterns, UI/import conventions, cn() usage, JS chunk cap (~500KB) and dynamic import guidance, and simplified testing/Storybook guidance.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • ikondrat
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and concisely summarizes the main change: condensing verbose frontend guidelines into a more streamlined format.
Description check ✅ Passed The description includes all required template sections (What has changed and why, How has it been tested, CHANGELOG.md status), though testing section appropriately notes N/A for documentation-only changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch michal-lig-9026-update-ai-instructions--4-condense-frontend

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ai_guidelines/frontend.md`:
- Line 28: The fenced code block in ai_guidelines/frontend.md (the
triple-backtick block around the src/ tree) is missing a language tag causing
markdownlint MD040; update the opening fence from ``` to ```text (or another
appropriate language identifier) so the block is explicitly labeled (e.g.,
change the opening fence of the src/ directory snippet in the code block to
```text).
- Line 233: The import example incorrectly includes a .ts extension; update the
documentation line that imports useCounter so it uses an extensionless import
(import { useCounter } from './useCounter';) to match the project's TypeScript
configuration and avoid implying allowImportingTsExtensions is enabled; locate
the example referencing useCounter and remove the ".ts" suffix from the import.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a909150b-f9f7-40cc-a2ea-f478f0a346b0

📥 Commits

Reviewing files that changed from the base of the PR and between 5556e83 and 744d98f.

📒 Files selected for processing (1)
  • ai_guidelines/frontend.md

Comment thread ai_guidelines/frontend.md
Comment thread ai_guidelines/frontend.md Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 744d98f410

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ai_guidelines/frontend.md
Comment thread ai_guidelines/frontend.md Outdated
Comment thread ai_guidelines/frontend.md Outdated
@bri-tong
Copy link
Copy Markdown

bri-tong commented Apr 1, 2026

Code Review: Condense frontend guidelines

Summary

This PR reduces ai_guidelines/frontend.md from ~1370 lines to ~300 lines (108 additions, 1174 deletions) — a ~78% reduction. The condensation is well-executed overall: core principles, patterns, and tooling choices are preserved while verbose explanations and redundant good/bad example pairs are removed. The result is a more scannable, reference-style document. A few areas lost nuance that may affect AI assistant comprehension when these guidelines are used as context.

Blocking Issues

None — this is a documentation-only change with no runtime impact.

Non-blocking Suggestions

1. Missing PageLoad import in the hooks/reactivity code example

File: ai_guidelines/frontend.md — Svelte 5 syntax section, hooks/reactivity example

The condensed snippet uses PageLoad type without importing it:

// +page.ts
export const load: PageLoad = async ({ params, url }) => {

The original had import type { PageLoad } from './$types';. Without it, an AI assistant following this pattern will produce code that doesn't compile.

Suggested fix:

// +page.ts
import type { PageLoad } from './$types';

export const load: PageLoad = async ({ params, url }) => {

2. "Do not mix the two approaches" is ambiguous

File: ai_guidelines/frontend.md — Reactive declarations line

Use $derived or derived() stores, not $:. Do not mix the two approaches - pick one per file/module.

"The two approaches" is vague — it could refer to $: vs $derived, or derived() vs $derived. The original had concrete bad/good examples showing the specific pitfall of mixing derived from svelte/store with the $derived rune.

Suggested fix:

Use $derived or derived() stores, not $:. Do not mix derived() stores with $derived runes in the same file/module — pick one approach per file.


3. Context API lost its code example

File: ai_guidelines/frontend.md — Avoiding props drilling section

The Context API (setContext/getContext) is a non-obvious pattern (string-keyed, type-cast) that was reduced to just a bullet point. Since this file is consumed by AI assistants that benefit from concrete patterns, consider keeping a minimal 5-10 line code example showing setContext in a parent and getContext in a child.


4. Integration test example fully removed

File: ai_guidelines/frontend.md — Testing section

The testing section now only shows a unit test example. The original had a concrete integration test showing fireEvent interaction patterns. Since the guidelines explicitly distinguish three testing levels, having at least a brief integration test example (even 5 lines) would make the distinction actionable rather than theoretical.


Questions / Clarifications

  • Is this file primarily consumed by AI coding assistants (e.g., as system prompt / context)? If so, the trade-off of brevity vs. concrete examples shifts toward keeping more examples for patterns that are non-obvious (Context API, Snippets, store/rune mixing pitfalls). If it's mainly for human developers who already know Svelte, the current condensation level is appropriate.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (2)
ai_guidelines/frontend.md (2)

28-28: ⚠️ Potential issue | 🟡 Minor

Add language tag to the fenced code block.

The code fence is missing a language identifier, causing markdownlint MD040 to fail.

Proposed fix
-```
+```text
 src/
   components/
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ai_guidelines/frontend.md` at line 28, The fenced code block closing/backtick
is missing a language tag; update the opening fence for that snippet (the ```
fence that precedes the "src/   components/" lines) to include a language
identifier such as "text" (i.e., change the opening ``` to ```text) so
markdownlint MD040 passes and the block is properly labeled.

253-253: ⚠️ Potential issue | 🟡 Minor

Remove .ts extension from import example.

The import example includes a .ts extension, but the repository's TypeScript configuration doesn't enable allowImportingTsExtensions. Use extensionless imports to match the project setup.

Proposed fix
-  import { useCounter } from './useCounter.ts';
+  import { useCounter } from './useCounter';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ai_guidelines/frontend.md` at line 253, The import example currently uses a
.ts extension which isn't supported by the project's TS config; update the
example to use an extensionless import for useCounter by removing ".ts" from the
import statement (look for the line importing useCounter and replace "import {
useCounter } from './useCounter.ts';" with an extensionless import).
🧹 Nitpick comments (2)
ai_guidelines/frontend.md (2)

8-8: Consider the 100-line limit's practical implications.

While concise components are generally beneficial, a strict 100-line limit may force artificial splits in cohesive logic. Consider adding guidance about when exceptions are acceptable (e.g., complex forms, state machines with many transitions).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ai_guidelines/frontend.md` at line 8, Update the guideline "Keep components
under 100 lines" to acknowledge practical exceptions: modify the rule text to
allow larger components when justified (e.g., complex forms, state machines with
many transitions, performance-optimized components) and add a short section
describing criteria for exemptions and examples of acceptable cases; reference
the original rule text ("Keep components under 100 lines") and add two brief
bullets: "When to split" and "When exceptions apply" with example scenarios and
a note to prefer extracting utilities/hooks for testable parts (so reviewers can
enforce intent rather than a hard line count).

202-202: Minor grammar suggestion.

Consider hyphenating "data fetching" as "data-fetching" when used as a compound adjective before "operations."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ai_guidelines/frontend.md` at line 202, Update the sentence "Implement proper
error handling for data fetching operations." in ai_guidelines/frontend.md to
hyphenate the compound adjective by changing it to "Implement proper error
handling for data-fetching operations." so the phrase is grammatically correct
when used before "operations."
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ai_guidelines/frontend.md`:
- Around line 87-94: The guideline's blanket rule "Avoid exporting/importing
types" is too restrictive; update ai_guidelines/frontend.md to allow exporting
explicit type definitions for public APIs and shared domain models (e.g., User,
ApiResponse) while keeping utility-derived types (Parameters<typeof
useData>/ReturnType<typeof useData> like UseDataParams, UseDataReturn,
TitleOnly, WithoutTitle) limited to internal/private use; specifically, change
the wording to permit exporting/importing types for public contracts and shared
models, add a short rationale and examples showing when to export a type vs
derive it from functions like useData, and mark utility derivation as an
acceptable pattern only for internal implementation surfaces.
- Around line 160-165: The +error.svelte component imports page from $app/stores
which violates the guideline; update the import to import page from "$app/state"
in +error.svelte and verify any usages of page (e.g., page.params or page.route)
still work without a $ prefix, adjusting code accordingly; after change, run a
quick build/test to ensure the error route compiles and behaves the same.

---

Duplicate comments:
In `@ai_guidelines/frontend.md`:
- Line 28: The fenced code block closing/backtick is missing a language tag;
update the opening fence for that snippet (the ``` fence that precedes the "src/
components/" lines) to include a language identifier such as "text" (i.e.,
change the opening ``` to ```text) so markdownlint MD040 passes and the block is
properly labeled.
- Line 253: The import example currently uses a .ts extension which isn't
supported by the project's TS config; update the example to use an extensionless
import for useCounter by removing ".ts" from the import statement (look for the
line importing useCounter and replace "import { useCounter } from
'./useCounter.ts';" with an extensionless import).

---

Nitpick comments:
In `@ai_guidelines/frontend.md`:
- Line 8: Update the guideline "Keep components under 100 lines" to acknowledge
practical exceptions: modify the rule text to allow larger components when
justified (e.g., complex forms, state machines with many transitions,
performance-optimized components) and add a short section describing criteria
for exemptions and examples of acceptable cases; reference the original rule
text ("Keep components under 100 lines") and add two brief bullets: "When to
split" and "When exceptions apply" with example scenarios and a note to prefer
extracting utilities/hooks for testable parts (so reviewers can enforce intent
rather than a hard line count).
- Line 202: Update the sentence "Implement proper error handling for data
fetching operations." in ai_guidelines/frontend.md to hyphenate the compound
adjective by changing it to "Implement proper error handling for data-fetching
operations." so the phrase is grammatically correct when used before
"operations."
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0fe0bd80-1d34-419f-be67-0e0f3501fc91

📥 Commits

Reviewing files that changed from the base of the PR and between 744d98f and cb7b0e3.

📒 Files selected for processing (1)
  • ai_guidelines/frontend.md

Comment thread ai_guidelines/frontend.md
Comment thread ai_guidelines/frontend.md
@michal-lightly
Copy link
Copy Markdown
Contributor Author

/review

@michal-lightly michal-lightly enabled auto-merge (squash) April 7, 2026 09:23
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
ai_guidelines/frontend.md (1)

28-28: ⚠️ Potential issue | 🟡 Minor

Add a language identifier to the fenced code block.

The code fence is still unlabeled, so markdownlint MD040 will continue to warn.

Proposed fix
-```
+```text
 src/
   components/
   ...
-```
+```
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ai_guidelines/frontend.md` at line 28, The fenced code block in
ai_guidelines/frontend.md is missing a language identifier (triggering
markdownlint MD040); update the opening fence from ``` to a labeled fence like
```text (or an appropriate language such as ```bash or ```json) so the block
reads ```text ... ``` and removes the linter warning.
🧹 Nitpick comments (3)
ai_guidelines/frontend.md (3)

265-269: Add a minimal Context API code example.

This section lists Context API as first choice but gives no example, which makes the guidance less actionable for assistants/readers.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ai_guidelines/frontend.md` around lines 265 - 269, The section names Svelte
Context API (setContext/getContext) but lacks an actionable example—add a
minimal, typed example showing how to call setContext in a parent component to
provide a value (e.g., an interface or store) and how a child uses getContext to
consume it; reference the symbols setContext/getContext and optionally the
Snippet type if demonstrating passing UI composition, ensure the example is
small (one parent and one child) and includes type annotations for clarity.

288-302: Include a short integration-test example to match the stated test levels.

You define unit/integration/E2E, but only show a unit sample. A compact interaction-based integration snippet would make the distinction concrete.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ai_guidelines/frontend.md` around lines 288 - 302, Add a compact
integration-test example showing component interaction (e.g., rendering a parent
or form component that composes child components and asserting user-driven state
changes) to match the stated test levels; update the examples block near the
unit test for MyComponent by adding a short integration snippet that uses render
+ user-event (or Svelte's fireEvent) to simulate user interaction across
components, then assert resulting DOM changes or emitted events (reference
MyComponent or a small ParentComponent/FormComponent composition) so readers can
see how integration tests differ from the unit test.

158-158: Use explicit terminology to distinguish the two reactive declaration approaches.

The phrase "do not mix the two approaches" is ambiguous and should name them directly. According to current Svelte 5 guidance, use:

  • "derived stores" for derived() from svelte/store
  • "$derived rune" (or "derived state") for the $derived rune

Suggested revision: "use $derived rune or derived() stores, not $:. Do not mix derived stores and $derived runes in the same file/module."

Additionally, consider recommending that imports of the derived function be renamed/aliased (e.g., import { derived as derivedStore } from 'svelte/store') to prevent mental confusion with the $derived rune, especially during migrations to runes mode.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ai_guidelines/frontend.md` at line 158, Update the "Reactive declarations"
line to explicitly name the two approaches — use "`$derived` rune" or "derived
stores" (the derived() function from svelte/store) instead of the vague phrase
"do not mix the two approaches"; change the sentence to: "use `$derived` rune or
`derived()` stores, not `$:`. Do not mix derived stores and `$derived` runes in
the same file/module." Also add a short recommendation to alias the imported
function to avoid confusion during migrations (e.g., suggest importing derived
as derivedStore with import { derived as derivedStore } from 'svelte/store') and
ensure references to `$derived`, `derived()` and `$:` are used exactly as
written so readers can find the symbols easily.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@ai_guidelines/frontend.md`:
- Line 28: The fenced code block in ai_guidelines/frontend.md is missing a
language identifier (triggering markdownlint MD040); update the opening fence
from ``` to a labeled fence like ```text (or an appropriate language such as
```bash or ```json) so the block reads ```text ... ``` and removes the linter
warning.

---

Nitpick comments:
In `@ai_guidelines/frontend.md`:
- Around line 265-269: The section names Svelte Context API
(setContext/getContext) but lacks an actionable example—add a minimal, typed
example showing how to call setContext in a parent component to provide a value
(e.g., an interface or store) and how a child uses getContext to consume it;
reference the symbols setContext/getContext and optionally the Snippet type if
demonstrating passing UI composition, ensure the example is small (one parent
and one child) and includes type annotations for clarity.
- Around line 288-302: Add a compact integration-test example showing component
interaction (e.g., rendering a parent or form component that composes child
components and asserting user-driven state changes) to match the stated test
levels; update the examples block near the unit test for MyComponent by adding a
short integration snippet that uses render + user-event (or Svelte's fireEvent)
to simulate user interaction across components, then assert resulting DOM
changes or emitted events (reference MyComponent or a small
ParentComponent/FormComponent composition) so readers can see how integration
tests differ from the unit test.
- Line 158: Update the "Reactive declarations" line to explicitly name the two
approaches — use "`$derived` rune" or "derived stores" (the derived() function
from svelte/store) instead of the vague phrase "do not mix the two approaches";
change the sentence to: "use `$derived` rune or `derived()` stores, not `$:`. Do
not mix derived stores and `$derived` runes in the same file/module." Also add a
short recommendation to alias the imported function to avoid confusion during
migrations (e.g., suggest importing derived as derivedStore with import {
derived as derivedStore } from 'svelte/store') and ensure references to
`$derived`, `derived()` and `$:` are used exactly as written so readers can find
the symbols easily.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 014379c9-1883-471f-8f15-a96267a2383e

📥 Commits

Reviewing files that changed from the base of the PR and between cb7b0e3 and 2663bcd.

📒 Files selected for processing (1)
  • ai_guidelines/frontend.md

@michal-lightly michal-lightly merged commit 59e0cb0 into main Apr 7, 2026
14 checks passed
@michal-lightly michal-lightly deleted the michal-lig-9026-update-ai-instructions--4-condense-frontend branch April 7, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants