Skip to content

[WIP] Set up shared package for components and utilities.#13259

Open
schultek wants to merge 4 commits intomainfrom
feat/site_shared
Open

[WIP] Set up shared package for components and utilities.#13259
schultek wants to merge 4 commits intomainfrom
feat/site_shared

Conversation

@schultek
Copy link
Copy Markdown
Contributor

@schultek schultek commented Apr 8, 2026

Adds a new site_shared package that contains components and other utilities for sharing with dart-lang/site-www.

  • Simply moved all components that are the same between both sites.
  • Moved and adapted components that exist on both sites but are slightly different (e.g. SiteSwitcher, Quiz)
  • Moved all styles related to a component that is also moved.
  • Moved the markdown rendering setup, which is the same for both sites.
  • Moved some utilities that are needed by components like analytics and code highlighting.

@schultek schultek requested a review from parlough April 8, 2026 11:47
@flutter-website-bot
Copy link
Copy Markdown
Collaborator

flutter-website-bot commented Apr 8, 2026

Visit the preview URL for this PR (updated for commit be6ce85):

https://flutter-docs-prod--pr13259-feat-site-shared-r2bqgfbp.web.app

@parlough parlough changed the title [WIP] Setup shared package for components and utilities. [WIP] Set up shared package for components and utilities. Apr 8, 2026
@schultek schultek marked this pull request as ready for review April 9, 2026 10:50
@schultek schultek requested review from a team and sfshaza2 as code owners April 9, 2026 10:50
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new site_shared package to centralize common components, utilities, and SCSS previously duplicated across the site and other packages. Key changes include extensive refactoring of SCSS imports, relocation of numerous Dart files to the new site_shared package with corresponding import path updates, and significant improvements to component handling and hydration logic, particularly for ComponentRef. Specific component updates include adding trailingIcon to Button, new parameters for CookieNotice and CopyButton, and refactoring quiz parsing in tutorial/quiz.dart. Review feedback points out two critical issues: inconsistent markdown parsing and weak validation in tutorial/quiz.dart for quizzes defined in tags, and a potential crash in util.dart's getOS() function due to web.window access during server-side rendering.

Comment on lines +52 to +57
final data = loadYamlNode(content);
assert(data is YamlList, 'Invalid Quiz content. Expected a YAML list.');
final questions = (data as YamlList).nodes
.map((n) => Question.fromMap(n as YamlMap))
.toList();
assert(questions.isNotEmpty, 'Quiz must contain at least one question.');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The current implementation has two issues:

  1. Inconsistent Parsing: Quizzes defined via tag content use Question.fromMap, while those loaded by ID use _parseQuestion. Since _parseQuestion explicitly handles markdown parsing via parseMarkdownToHtml, quizzes defined directly in tags will likely fail to render markdown correctly (showing raw markdown text instead of HTML).
  2. Weak Validation: Using assert for input validation is insufficient for production builds where assertions are disabled. If the YAML structure is incorrect, the code will throw a TypeError during the cast to YamlList instead of providing a descriptive error message.
    final data = loadYamlNode(content);
    if (data is! YamlList) {
      throw ArgumentError('Invalid Quiz content. Expected a YAML list.');
    }
    final questions = data.nodes
        .map((n) => _parseQuestion(n as YamlMap))
        .toList();
    if (questions.isEmpty) {
      throw ArgumentError('Quiz must contain at least one question.');
    }

Comment on lines +130 to +131
OperatingSystem? getOS() {
final userAgent = web.window.navigator.userAgent;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The getOS() function accesses web.window, which is not available during server-side rendering (SSR) and will cause a crash. Since this is a shared utility, it should be environment-aware. Note: You will need to import package:jaspr/jaspr.dart to use kIsWeb.

OperatingSystem? getOS() {
  if (!kIsWeb) return null;
  final userAgent = web.window.navigator.userAgent;

Copy link
Copy Markdown
Contributor

@sfshaza2 sfshaza2 left a comment

Choose a reason for hiding this comment

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

lgtm. I leave it to you, @schultek, to fix the build issues.

@parlough parlough self-assigned this Apr 9, 2026
@parlough
Copy link
Copy Markdown
Member

parlough commented Apr 9, 2026

Thanks for tackling this Kilian! I'm excited.

Hold off on landing this. I'd like to take a look first. I should have time early next week.

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.

4 participants