Skip to content

Bundle size optimization and hash handling fixes#25

Merged
sv2dev merged 4 commits intomainfrom
bundle-size-improvements
Mar 31, 2026
Merged

Bundle size optimization and hash handling fixes#25
sv2dev merged 4 commits intomainfrom
bundle-size-improvements

Conversation

@sv2dev
Copy link
Copy Markdown
Owner

@sv2dev sv2dev commented Mar 31, 2026

Summary

  • Bundle size: Removed debug logging, dead code, optimized array syntax, added sideEffects flag
  • Bug fix: Hash now properly included in href generation and maintained through redirects
  • Tests: Added 3 new test cases for hash handling

Changes

  • Remove console.log debug statement from scroll-restoration
  • Remove dead code (if (save) check) in scroll-restoration
  • Fix href getter to include hash when constructing from path array
  • Forward hash when reconstructing NavOpts after redirects
  • Replace new Array<T>() with [] for smaller compiled output
  • Add sideEffects: false to both package.json files for better tree-shaking

Test plan

  • All 58 tests pass (55 existing + 3 new)
  • npm run build succeeds
  • New tests cover hash in href scenarios

Summary by CodeRabbit

  • New Features

    • Added full support for hash fragments (#) in URLs and navigation
  • Bug Fixes

    • Hash fragments now properly propagate through router state updates
    • Resolved debug console output appearing in scroll restoration
  • Tests

    • Added test cases for hash fragment inclusion in URL construction
  • Chores

    • Optimized bundle packaging with side-effects declaration
    • Packages updated to version 0.12.1

Sven Rogge added 2 commits April 1, 2026 00:36
- Remove debug console.log from scroll-restoration.ts
- Remove dead code (if (save) wrapper) in scroll-restoration.ts
- Fix href getter to include hash when constructing from path array
- Forward hash when reconstructing NavOpts in redirects
- Replace new Array<T>() with [] for smaller compiled output
- Add sideEffects: false to package.json for better tree-shaking
- Add tests for href with hash
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

Warning

Rate limit exceeded

@sv2dev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 24 minutes and 25 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 24 minutes and 25 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a62f5bca-8e9b-47f3-87a4-27557d1b4698

📥 Commits

Reviewing files that changed from the base of the PR and between 0550e54 and 67aee83.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • packages/esroute/src/scroll-restoration.ts

Walkthrough

This pull request increments the esroute and esroute-lit packages from version 0.12.0 to 0.12.1, adds hash fragment support to the NavOpts routing class, updates package manifests with sideEffects: false declarations, adds tests for hash handling, refactors array initialization, and adjusts scroll restoration event listener registration while removing debug logging.

Changes

Cohort / File(s) Summary
Package Configuration
packages/esroute-lit/package.json, packages/esroute/package.json
Version bumped to 0.12.1; esroute dependency updated to ^0.12.1; added sideEffects: false to both manifests for tree-shaking optimization.
Hash Fragment Feature
packages/esroute/src/nav-opts.ts, packages/esroute/src/nav-opts.spec.ts
NavOpts.href now conditionally appends hash fragments (#${hash}) to constructed URLs; added comprehensive test cases verifying hash handling in various instantiation scenarios.
Type Refactoring
packages/esroute/src/route-resolver.ts
Array initialization refactored from new Array<NavOpts<S>>() to typed literal [] syntax with explicit NavOpts<S>[] annotation.
Router State Propagation
packages/esroute/src/router.ts
Updated state replacement logic to propagate opts.hash into newly constructed NavOpts during route updates.
Scroll Restoration Updates
packages/esroute/src/scroll-restoration.ts
Removed conditional guards around beforeunload and visibilitychange listener registration (now always registered); removed debug console.log statement.

Possibly related PRs

Poem

🐰 A hash upon the path we go,
Tree-shaking winds now gently blow,
Tests confirm our fragments true,
Router state flows bold and new,
Scroll restored without a sound!

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: bundle size optimizations (sideEffects flags, removed console.log, code simplifications) and hash handling fixes (href getter and redirect forwarding).
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 bundle-size-improvements

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

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/esroute/src/nav-opts.ts (1)

52-53: ⚠️ Potential issue | 🟠 Major

href cache can ignore explicit opts.hash overrides.

When constructed from an href plus { hash }, _h may be cached before the override is applied, so href returns the old fragment.

🔧 Proposed fix
-      if (!search) this._h = href;
+      // Cache only when no explicit hash override is provided.
+      if (!search && hash == null) this._h = href;

Also applies to: 63-63, 73-77

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

In `@packages/esroute/src/nav-opts.ts` around lines 52 - 53, The cached href
stored in this._h can be set from the original href before applying an explicit
opts.hash override, causing href to return the old fragment; update the logic in
the constructor/initializer that sets this._h so it incorporates opts.hash (or
clears/overwrites the fragment) after parsing href (the code around the
variables href, _h, search, pathString, searchString, hash) — specifically, when
opts.hash is present compute or rebuild the final href using pathString and
searchString plus opts.hash (or assign this._h = rebuiltHref) instead of keeping
the original href; apply the same adjustment to the other similar spots
indicated (the blocks around the lines referenced at 63 and 73–77) so caching
always reflects any explicit opts.hash override.
🧹 Nitpick comments (1)
packages/esroute/src/nav-opts.spec.ts (1)

100-115: Add a regression case for href + explicit hash override.

Current additions are good, but they don’t cover new NavOpts("/foo#old", { hash: "new" }), which is where stale href caching can regress.

🧪 Suggested test
   describe("href with hash", () => {
@@
     it("should include hash in href when constructed from StrictNavMeta", () => {
       const opts = new NavOpts({ path: ["foo"], hash: "bar" });
       expect(opts.href).toBe("/foo#bar");
     });
+
+    it("should prefer explicit opts.hash over hash parsed from href", () => {
+      const opts = new NavOpts("/foo#old", { hash: "new" });
+      expect(opts.href).toBe("/foo#new");
+    });
   });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/esroute/src/nav-opts.spec.ts` around lines 100 - 115, Add a
regression test to ensure NavOpts correctly applies an explicit hash override
when constructed from a string that already contains a hash: create a test that
constructs NavOpts with a base like "/foo#old" and options { hash: "new" } and
assert opts.href === "/foo#new"; target the NavOpts constructor behavior and its
href property to catch stale caching of the original hash (referencing NavOpts
and href).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/esroute/src/scroll-restoration.ts`:
- Around line 35-36: Change the visibilitychange listener to be attached to
document instead of window: locate the lines that add the event listeners (the
save function is used in window.addEventListener("beforeunload", save) and
window.addEventListener("visibilitychange", save)) and replace the
visibilitychange registration so it calls
document.addEventListener("visibilitychange", save) while leaving beforeunload
on window unchanged; ensure you only update the listener attachment target and
keep the save handler unchanged.

---

Outside diff comments:
In `@packages/esroute/src/nav-opts.ts`:
- Around line 52-53: The cached href stored in this._h can be set from the
original href before applying an explicit opts.hash override, causing href to
return the old fragment; update the logic in the constructor/initializer that
sets this._h so it incorporates opts.hash (or clears/overwrites the fragment)
after parsing href (the code around the variables href, _h, search, pathString,
searchString, hash) — specifically, when opts.hash is present compute or rebuild
the final href using pathString and searchString plus opts.hash (or assign
this._h = rebuiltHref) instead of keeping the original href; apply the same
adjustment to the other similar spots indicated (the blocks around the lines
referenced at 63 and 73–77) so caching always reflects any explicit opts.hash
override.

---

Nitpick comments:
In `@packages/esroute/src/nav-opts.spec.ts`:
- Around line 100-115: Add a regression test to ensure NavOpts correctly applies
an explicit hash override when constructed from a string that already contains a
hash: create a test that constructs NavOpts with a base like "/foo#old" and
options { hash: "new" } and assert opts.href === "/foo#new"; target the NavOpts
constructor behavior and its href property to catch stale caching of the
original hash (referencing NavOpts and href).
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 61a81ce8-9d60-4beb-a01f-61db282ad358

📥 Commits

Reviewing files that changed from the base of the PR and between 097996d and 0550e54.

📒 Files selected for processing (7)
  • packages/esroute-lit/package.json
  • packages/esroute/package.json
  • packages/esroute/src/nav-opts.spec.ts
  • packages/esroute/src/nav-opts.ts
  • packages/esroute/src/route-resolver.ts
  • packages/esroute/src/router.ts
  • packages/esroute/src/scroll-restoration.ts

Sven Rogge added 2 commits April 1, 2026 00:52
Adds a Keep a Changelog formatted changelog documenting all releases from v0.1.0 through v0.12.1, including features, fixes, and breaking changes for each version.
@sv2dev sv2dev merged commit e3b6069 into main Mar 31, 2026
2 checks passed
@sv2dev sv2dev deleted the bundle-size-improvements branch March 31, 2026 22:55
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.

1 participant