Skip to content

Conversation

Henry8192
Copy link
Contributor

@Henry8192 Henry8192 commented Aug 11, 2025

Description

Fixes #356.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Open this URL: http://localhost:3010/?filePath=https://yscope.s3.us-east-2.amazonaws.com/sample-logs/yarn-ubuntu-resourcemanager-ip-172-31-17-135.log.1.clp.zst#logEventNum=375558&isPrettified=true
Notice that the isPrettified=true parameter is kept.

Summary by CodeRabbit

  • Bug Fixes

    • The “Prettified” view now correctly reads and syncs the URL hash parameter on initial page load and when a log file is loaded, ensuring shared/bookmarked links show the intended formatting.
  • Chores

    • Internal synchronization added so view preferences are propagated to the log manager before page data loads; no public API or behavioural changes.

@Henry8192 Henry8192 requested a review from a team as a code owner August 11, 2025 21:35
Copy link

coderabbitai bot commented Aug 11, 2025

Walkthrough

AppController now reads isPrettified from URL hash params using HASH_PARAM_NAMES on initial load and calls setIsPrettified(hashParams.isPrettified). logFileStore reads the view store's isPrettified and calls/awaits LogFileManager.setIsPrettified before loading page data. No public API changes.

Changes

Cohort / File(s) Summary
AppController — URL hash sync
src/components/AppController.tsx
Import HASH_PARAM_NAMES; read isPrettified from parsed hash params on initial load; call setIsPrettified(hashParams.isPrettified); updateWindowUrlHashParams uses the hash-derived value.
Log file load — propagate prettify to manager
src/stores/logFileStore.ts
After setting file info, read isPrettified from the view store and await logFileManagerProxy.setIsPrettified(isPrettified) before loading page data.

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant AppController
  participant URLHashParser
  participant ViewStore
  participant LogFileStore
  participant LogFileManager

  Browser->>AppController: Load page
  AppController->>URLHashParser: Parse hash params
  URLHashParser-->>AppController: { isPrettified, ... }
  AppController->>ViewStore: setIsPrettified(isPrettified)
  AppController->>LogFileStore: trigger file load
  LogFileStore->>ViewStore: read isPrettified
  LogFileStore->>LogFileManager: await setIsPrettified(isPrettified)
  LogFileStore->>LogFileStore: load page data
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Assessment against linked issues

Objective Addressed Explanation
Preserve isPrettified parameter from URL on initial load (#356)
Shareable links keep prettified state intact (#356) Copy/link generation code not modified here; unclear if link creation includes hash param.

Possibly related PRs

Suggested reviewers

  • junhaoliao
  • hoophalab
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Henry8192 Henry8192 requested a review from hoophalab August 11, 2025 21:36
Copy link

@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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eac74c6 and 32ca55c.

📒 Files selected for processing (1)
  • src/components/AppController.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}

⚙️ CodeRabbit Configuration File

  • Prefer false == <expression> rather than !<expression>.

Files:

  • src/components/AppController.tsx
🧠 Learnings (3)
📚 Learning: 2024-10-19T03:33:29.578Z
Learnt from: junhaoliao
PR: y-scope/yscope-log-viewer#94
File: new-log-viewer/src/components/CentralContainer/Sidebar/index.tsx:99-118
Timestamp: 2024-10-19T03:33:29.578Z
Learning: In `new-log-viewer/src/components/CentralContainer/Sidebar/index.tsx`, when using `useEffect` to register window resize event handlers, it's acceptable to have an empty dependency array because the variables and functions used within the effect (`getPanelWidth`, `PANEL_CLIP_THRESHOLD_IN_PIXELS`, and `tabListRef`) are constants or refs declared outside the functional component and do not change.

Applied to files:

  • src/components/AppController.tsx
📚 Learning: 2025-06-01T13:40:12.222Z
Learnt from: zzxthehappiest
PR: y-scope/yscope-log-viewer#286
File: src/components/Editor/index.tsx:138-139
Timestamp: 2025-06-01T13:40:12.222Z
Learning: In the yscope-log-viewer codebase, when using Zustand stores in React components, the preferred pattern is to use `getState()` for static setters that never change (like `setLogEventNum`) to avoid unnecessary subscriptions, while using hooks for actions that do more than just setting values. All store state variables should be declared at the beginning of the component for consistency and clear dependency overview.

Applied to files:

  • src/components/AppController.tsx
📚 Learning: 2025-06-01T13:41:12.938Z
Learnt from: zzxthehappiest
PR: y-scope/yscope-log-viewer#286
File: src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/QueryInputBox.tsx:37-40
Timestamp: 2025-06-01T13:41:12.938Z
Learning: The `updateWindowUrlHashParams` function in `src/utils/url.ts` doesn't throw errors, so error handling is not needed when calling this function.

Applied to files:

  • src/components/AppController.tsx
🧬 Code Graph Analysis (1)
src/components/AppController.tsx (1)
src/typings/url.ts (1)
  • HASH_PARAM_NAMES (39-39)
🪛 GitHub Check: lint-check
src/components/AppController.tsx

[failure] 6-6:
There should be no space before '}'


[failure] 6-6:
There should be no space after '{'


[failure] 6-6:
Expected a line break after this opening brace


[failure] 6-6:
Imports must be broken into multiple lines if there are more than 1 elements


[failure] 1-1:
Expected a line break before this closing brace


[failure] 1-1:
There should be no space before '}'


[failure] 1-1:
There should be no space after '{'


[failure] 1-1:
Expected a line break after this opening brace


[failure] 1-1:
Run autofix to sort these imports!


[failure] 1-1:
Imports must be broken into multiple lines if there are more than 1 elements

🪛 GitHub Actions: lint
src/components/AppController.tsx

[error] 1-1: ESLint: Imports must be broken into multiple lines if there are more than 1 elements. (import-newlines/enforce)

🔇 Additional comments (2)
src/components/AppController.tsx (2)

57-57: Excellent fix for preserving isPrettified parameter from URL hash.

This change correctly addresses issue #356 by using the actual isPrettified value from the URL hash parameters instead of the default value. When users share URLs with isPrettified=true, this ensures the prettified state is preserved on initial page load.


54-62: LGTM! Clean and targeted fix that preserves URL state consistency.

The implementation correctly addresses the PR objectives by ensuring isPrettified parameter preservation on initial page load. The approach maintains both URL state (line 57) and application state (line 61) consistency, allowing users to share URLs with maintained prettified state.

Copy link

@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: 1

🔭 Outside diff range comments (2)
src/components/AppController.tsx (2)

63-71: Use a single, typed source of truth for isPrettified and add a fallback.

Avoid mixing bracket-index and dot-prop access. Derive once from the hash using HASH_PARAM_NAMES and use that for both the URL update and the view store, with a safe default in case the param is absent.

         const hashParams = getWindowUrlHashParams();
-        updateWindowUrlHashParams({
-            isPrettified: hashParams[HASH_PARAM_NAMES.IS_PRETTIFIED],
-            timestamp: URL_HASH_PARAMS_DEFAULT.timestamp,
-        });
-        const {setIsPrettified} = useViewStore.getState();
-        setIsPrettified(hashParams.isPrettified);
+        const isPrettifiedFromUrl =
+            hashParams[HASH_PARAM_NAMES.IS_PRETTIFIED] ?? URL_HASH_PARAMS_DEFAULT.isPrettified;
+        updateWindowUrlHashParams({
+            isPrettified: isPrettifiedFromUrl,
+            timestamp: URL_HASH_PARAMS_DEFAULT.timestamp,
+        });
+        const {setIsPrettified} = useViewStore.getState();
+        setIsPrettified(isPrettifiedFromUrl);

57-61: StrictMode gotcha: early-return guard can drop the event listener in dev.

With React 18 StrictMode, effects mount/cleanup twice in dev. Returning early with isInitialized.current can skip re-adding the handler after the intentional cleanup, leaving no listener. Consider removing this guard and relying on cleanup/idempotent code instead.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 32ca55c and 5401a43.

📒 Files selected for processing (1)
  • src/components/AppController.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}

⚙️ CodeRabbit Configuration File

  • Prefer false == <expression> rather than !<expression>.

Files:

  • src/components/AppController.tsx
🧠 Learnings (1)
📚 Learning: 2025-06-01T13:41:12.938Z
Learnt from: zzxthehappiest
PR: y-scope/yscope-log-viewer#286
File: src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/QueryInputBox.tsx:37-40
Timestamp: 2025-06-01T13:41:12.938Z
Learning: The `updateWindowUrlHashParams` function in `src/utils/url.ts` doesn't throw errors, so error handling is not needed when calling this function.

Applied to files:

  • src/components/AppController.tsx
🧬 Code Graph Analysis (1)
src/components/AppController.tsx (1)
src/typings/url.ts (1)
  • HASH_PARAM_NAMES (39-39)
🔇 Additional comments (1)
src/components/AppController.tsx (1)

9-9: Import fix looks good (formatting and path).

Using a single-element named import without the “.ts” extension aligns with the lint rules and TS conventions.

Copy link
Contributor

@hoophalab hoophalab left a comment

Choose a reason for hiding this comment

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

I confirm that isPrettified argument isn't deleted in the url, but somehow it isn't applied? Like the toggle button is down, but the content isn't actually prettified

@Henry8192
Copy link
Contributor Author

I confirm that isPrettified argument isn't deleted in the url, but somehow it isn't applied? Like the toggle button is down, but the content isn't actually prettified

Good catch. Since we refactored loadPage without the isPrettified parameter, we should notify logFileManager to change isPrettified during the initial page load.

Copy link

@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: 1

🔭 Outside diff range comments (1)
src/stores/logFileStore.ts (1)

119-127: Remove redundant state/URL updates (duplicate fileSrc set and FILE_PATH clearing)

fileSrc is set twice (Lines 120–124 and again on Line 141), and updateWindowUrlSearchParams is called twice with the same condition. Keep the first block and drop the second to reduce unnecessary state writes and URL manipulations.

-        set({fileSrc});
-        if ("string" !== typeof fileSrc) {
-            updateWindowUrlSearchParams({[SEARCH_PARAM_NAMES.FILE_PATH]: null});
-        }

Also applies to: 141-144

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5401a43 and 3d5bfe0.

📒 Files selected for processing (1)
  • src/stores/logFileStore.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}

⚙️ CodeRabbit Configuration File

  • Prefer false == <expression> rather than !<expression>.

Files:

  • src/stores/logFileStore.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build (macos-latest)
🔇 Additional comments (1)
src/stores/logFileStore.ts (1)

161-163: Correct sequencing: apply prettified state before loading page data

Setting/awaiting setIsPrettified before loadPage(cursor) ensures the initial page renders with the intended formatting. This directly addresses the regression in #356.

Copy link
Contributor

@hoophalab hoophalab left a comment

Choose a reason for hiding this comment

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

looks good to me

Validations:
#356 is fixed

@hoophalab
Copy link
Contributor

hoophalab commented Aug 13, 2025

PR title:
how about update -> Update
fix: Update isPrettified handling on initial page load (fixes #356).

Copy link
Member

@kirkrodrigues kirkrodrigues left a comment

Choose a reason for hiding this comment

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

Deferring to @hoophalab's review.

@kirkrodrigues kirkrodrigues changed the title fix: update isPrettified handling on initial page load (fixes #356). fix: Update isPrettified handling on initial page load (fixes #356). Aug 13, 2025
@hoophalab hoophalab merged commit 3abe4cc into y-scope:main Aug 13, 2025
7 checks passed
@Henry8192 Henry8192 deleted the preserve-isPrettified-upon-file-load branch August 13, 2025 21:46
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.

isPrettified parameter gets discarded from URLs
3 participants