Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] cleanup Router and Renderer #4101

Closed
wants to merge 4 commits into from
Closed

Conversation

benmccann
Copy link
Member

@benmccann benmccann commented Feb 24, 2022

I know there's been some talk of combining Router and Renderer into a single class, but I think the original idea of having separate Router and Renderer implementation came from a good place and we just never implemented it very well

The benefits of having a separate Router and Renderer include being able to hydrate without loading the Router code
and more possibilities for improved Router testing.

This removes renderer as a field from Router. By removing cycles between the two classes, it's far easier to understand what's happening and what should happen where. One of the main things needed to accomplish this is to move prefetching to the Renderer. It makes more sense in Renderer than Router since it almost renders the page by calling load, etc. whereas the Router is meant to be just related to navigation

Things this PR cleans up the API quite a bit. The set of public methods on the two classes is much saner now.

@changeset-bot
Copy link

changeset-bot bot commented Feb 24, 2022

⚠️ No Changeset found

Latest commit: 70bceab

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Rich-Harris
Copy link
Member

Is this intended as an alternative to combining them into a single Client class? I was planning to address any outstanding PRs that affect this code (like #3629, possibly others? not sure) before touching it, so that they don't get stale

addEventListener('touchstart', trigger_prefetch);
addEventListener('mousemove', handle_mousemove);
addEventListener('sveltekit:trigger_prefetch', trigger_prefetch);
addEventListener('hashchange', () => this._update_page_store(new URL(window.location.href)));
Copy link
Contributor

@PH4NTOMiki PH4NTOMiki Mar 1, 2022

Choose a reason for hiding this comment

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

Inside this event listener needs to be that if (hash_navigating) that gets inited as false, and mutated to true in click event listener if the navigation only changes hash, and also inside it needs to have that history.replaceState.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I just checked and you have duplicate for every event listener, so this is probably WIP still, or?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ummm. I'm pretty sure there is not a duplicate for every event listener unless I'm missing something. There are two hashchange listeners though, which I hadn't noticed. Perhaps they should be combined so that the handlers execute in a consistent order

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I saw those 2 and assumed that there are more duplicates, sorry for that, but if that's the case then I guess we can merge them, if code should be after that other one for consistency.

@Rich-Harris Rich-Harris mentioned this pull request Mar 1, 2022
5 tasks
@benmccann
Copy link
Member Author

Closing in favor of #4161 after discussion with the other maintainers

@benmccann benmccann closed this Mar 2, 2022
@benmccann benmccann deleted the router-refactor-2 branch March 2, 2022 22:06
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