Skip to content

Remove watched routes by the file that added them - #30

Open
everton-dgn wants to merge 1 commit into
solidjs:mainfrom
everton-dgn:fix/remove-route-by-source
Open

everton-dgn wants to merge 1 commit into
solidjs:mainfrom
everton-dgn:fix/remove-route-by-source

Conversation

@everton-dgn

Copy link
Copy Markdown

Fixes #29

removeRoute found the entry with toPath(src), which is not always the path that src produced. #29 has the cases and a repro.

  • The router records the route path each source file produced, in addRoute and updateRoute. removeRoute looks the path up there and does nothing for a file without a record. Falling back to toPath would bring back the about.ts case, where toPath gives the path of another file.
  • removeRoute no longer calls toPath, so BaseFileSystemRouter with only toRoute stops throwing. It also drops the isRoute check, since a recorded file passed it when it was added.
  • When addRoute or updateRoute gets a path for a file that differs from the recorded one, it removes the old entry first. The router emits remove for the old path, then add for the new one.

When two files map to the same path (for example about.mdx and about.tsx), removing either one still removes the entry, as before. The other file keeps its record, so a later save of it adds the entry back.

A subclass that calls _addRoute directly bypasses the record, so removeRoute does nothing for its files. Nothing in this repo does that; FlatFileSystemRouter only overrides toPath.

This is independent of #28. Both add a map to BaseFileSystemRouter: #28 records the first source file per path, for ordering, and this one records the path per source file, for removal. They touch the same methods, so whichever lands second needs a small rebase.

The three new tests in test/convention.spec.ts cover:

  • a helper module next to a page;
  • a custom toRoute through path changes on change and add, an edit that makes it return undefined, and a delete;
  • BaseFileSystemRouter with only toRoute.

All three fail on main.

removeRoute looked the entry up with toPath, which is not always the path the file produced. Saving or deleting a module that isn't a route removed a page with the same path, an entry from a custom toRoute outlived its file, and BaseFileSystemRouter with only toRoute threw on delete. Record the path each file produced and remove by that record.
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.

removeRoute looks up the entry with toPath, not the path the file produced

1 participant