fix(router): remove setInitialState override pattern from SPA navigation#223
Merged
mohamedmansour merged 1 commit intomainfrom Apr 13, 2026
Merged
Conversation
The router previously checked for a user-defined setInitialState method on route components and fell back to applyStateAsAttributes when absent. This created two problems: 1. App developers were overriding setInitialState to manually assign @observable and @attr properties — duplicating what the framework base class already does automatically. Every override was a potential source of bugs (missed properties, wrong types, stale state). 2. Route params (e.g. :folderId, :threadId) were passed as a second argument to setInitialState, mixing concerns. Params are HTML attributes that @attr reflects; state is JSON that @observable consumes. These are two different mechanisms. Changes: - Router now always calls the framework's built-in setInitialState(state) which sets @observable properties and synchronously flushes DOM updates via \(). No override needed or supported. - Route params are set as HTML attributes (kebab-case) before setInitialState, so @attr reflection handles them automatically. E.g. params.threadId becomes attribute thread-id on the element. - Removed applyStateAsAttributes fallback — the framework's setInitialState + \ handles all cases: scalars via @observable setters, arrays/objects via complex property bindings with synchronous child flush. - Moved isInitialNavigation flag before async work to prevent a race condition where a user click during SSR bootstrap component loading could re-enter the initial navigation path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
janechu
approved these changes
Apr 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The router previously checked for a user-defined setInitialState method on route components and fell back to applyStateAsAttributes when absent. This created two problems:
App developers were overriding setInitialState to manually assign @observable and @attr properties — duplicating what the framework base class already does automatically. Every override was a potential source of bugs (missed properties, wrong types, stale state).
Route params (e.g. :folderId, :threadId) were passed as a second argument to setInitialState, mixing concerns. Params are HTML attributes that @attr reflects; state is JSON that @observable consumes. These are two different mechanisms.
Changes:
Router now always calls the framework's built-in setInitialState(state) which sets @observable properties and synchronously flushes DOM updates via (). No override needed or supported.
Route params are set as HTML attributes (kebab-case) before setInitialState, so @attr reflection handles them automatically. E.g. params.threadId becomes attribute thread-id on the element.
Removed applyStateAsAttributes fallback — the framework's setInitialState + \ handles all cases: scalars via @observable setters, arrays/objects via complex property bindings with synchronous child flush.
Moved isInitialNavigation flag before async work to prevent a race condition where a user click during SSR bootstrap component loading could re-enter the initial navigation path.