Skip to content

feat: first-class TanStack Router plugin integration#8317

Open
BleedingDev wants to merge 6 commits into
web-infra-dev:mainfrom
BleedingDev:feat/tanstack-router-tailwind-first-class
Open

feat: first-class TanStack Router plugin integration#8317
BleedingDev wants to merge 6 commits into
web-infra-dev:mainfrom
BleedingDev:feat/tanstack-router-tailwind-first-class

Conversation

@BleedingDev
Copy link
Copy Markdown

@BleedingDev BleedingDev commented Feb 6, 2026

Summary

  • add first-class TanStack Router support as @modern-js/plugin-tanstack, keeping TanStack packages out of @modern-js/runtime
  • add generic router CLI/runtime SSR extension seams so plugin-owned routers can participate in route generation, SSR data snapshots, hydration scripts, and cleanup
  • add TanStack route generation/runtime coverage for loaders, actions/mutations, redirects, notFound handling, optional params, route static data, navigation blockers, and prefetch links
  • add focused integration fixtures for TanStack SSR/data-flow and generated route contracts
  • update EN/ZH docs to clarify router-specific runtime exports (@modern-js/runtime/router vs @modern-js/plugin-tanstack/runtime)

Validation

  • pnpm exec biome check --files-ignore-unknown=true ...
  • pnpm --filter @modern-js/plugin-tanstack build
  • pnpm --filter @modern-js/plugin-tanstack test
  • pnpm --filter @modern-js/runtime build
  • pnpm --dir packages/runtime/plugin-runtime exec rstest run tests/router/cliExtension.test.ts tests/router/entryOwnership.test.ts tests/router/lifecycle.test.tsx tests/core/react/wrapper.test.tsx tests/ssr/serverRender/renderToStream/buildTemplate.before.test.ts tests/ssr/serverRender/renderToStream/buildTemplate.after.test.ts tests/ssr/serverRender/renderToString/entry.test.ts tests/ssr/serverRender/requestHandler.test.tsx --passWithNoTests
  • pnpm --dir tests exec rstest run -c rstest.superapp-contracts.config.mts
  • pnpm --dir tests/integration/routes-tanstack build
  • pnpm --dir tests/integration/routes-tanstack-create-routes build

@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 6, 2026

Deploy Preview for modernjs-v3 ready!

Name Link
🔨 Latest commit 0f32a7f
🔍 Latest deploy log https://app.netlify.com/projects/modernjs-v3/deploys/6985a2c18d6af60008a29a27
😎 Deploy Preview https://deploy-preview-8317--modernjs-v3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 6, 2026

🦋 Changeset detected

Latest commit: 2a3ac76

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 120 packages
Name Type
@modern-js/runtime Minor
@modern-js/plugin-tanstack Minor
@modern-js/plugin-bff Minor
@modern-js/plugin-styled-components Minor
@modern-js/plugin-i18n Minor
@integration-test/alias-set Patch
app-document Patch
async-entry-test Patch
tmp Patch
bff-api-app Patch
bff-client-app Patch
bff-indep-client-app Patch
bff-hono Patch
integration-clean-dist-path Patch
integration-compatibility Patch
integration-custom-dist-path Patch
custom-file-system-entry Patch
integration-custom-template Patch
deploy Patch
deploy-server Patch
dev-server Patch
integration-disable-html Patch
app-custom-entries Patch
app-custom-routes-runtime Patch
app-custom Patch
app-entry Patch
app-route Patch
app-entry-server Patch
i18n-app-csr-html-lang Patch
i18n-app Patch
i18n-app-ssr-html-lang Patch
i18n-app-ssr Patch
i18n-custom-i18n-wrapper Patch
i18n-mf-app-provider Patch
i18n-mf-component-provider Patch
i18n-mf-consumer Patch
i18n-routes Patch
i18n-routes-ssr Patch
@integration-test/image-component Patch
main-entry-name Patch
nonce Patch
pure-esm-project Patch
routes-match Patch
routes-tanstack-create-routes Patch
routes-tanstack Patch
routes Patch
app-rsbuild-hooks Patch
rsc-csr-app Patch
rsc-csr-routes Patch
rsc-ssr-app Patch
rsc-ssr-routes Patch
basic-app-rstest-browser Patch
basic-app-rstest Patch
runtime-custom-plugin Patch
runtime-custom-config-plugin Patch
select-mul-entry-test Patch
select-one-entry-test Patch
server-config Patch
server-json-script Patch
server-monitors Patch
server-prod Patch
server-routes Patch
@source-code-build/app Patch
ssg-fixtures-mega-list-routes Patch
ssg-fixtures-nested-routes Patch
ssg-fixtures-simple Patch
ssg-fixtures-web-server Patch
ssr-base-async-entry-test Patch
ssr-base-async-pre-entry-test Patch
ssr-base-json-test Patch
ssr-base-test Patch
ssr-base-fallback-test Patch
init Patch
ssr-base-loadable Patch
ssr-partial-test Patch
rsc-closing-tags-test Patch
ssr-script-loading Patch
ssr-useid-test Patch
ssr-streaming-inline-test Patch
ssr-streaming-test Patch
integration-storybook Patch
styled-components-stream Patch
styled-components-string Patch
integration-tailwindcss-v2 Patch
integration-tailwindcss-v3 Patch
integration-tailwindcss-v4-tools Patch
integration-tailwindcss-v4 Patch
tmp-dir Patch
write-to-dist Patch
@modern-js/bundle-diff-benchmark Minor
@modern-js/main-doc Minor
@modern-js/tsconfig Minor
@modern-js/adapter-rstest Minor
@modern-js/builder Minor
@modern-js/plugin-data-loader Minor
@modern-js/plugin-ssg Minor
@modern-js/image Minor
@modern-js/render Minor
@modern-js/bff-core Minor
@modern-js/bff-runtime Minor
@modern-js/server-core Minor
@modern-js/create-request Minor
@modern-js/plugin-polyfill Minor
@modern-js/prod-server Minor
@modern-js/server-runtime Minor
@modern-js/server Minor
@modern-js/server-utils Minor
@modern-js/app-tools Minor
@modern-js/create Minor
@modern-js/i18n-utils Minor
@modern-js/plugin Minor
@modern-js/runtime-utils Minor
@modern-js/sandpack-react Minor
@modern-js/types Minor
@modern-js/utils Minor
@modern-js/rslib Minor
@scripts/prebundle Patch
@scripts/rstest-config Patch
entries-app-builder Patch
@scripts/release-node Patch

Not sure what this means? Click here to learn what changesets are.

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

@caohuilin
Copy link
Copy Markdown
Member

caohuilin commented Feb 10, 2026

Thanks for the contribution! We are currently reviewing and discussing this PR, and will provide feedback soon.

@zllkjc
Copy link
Copy Markdown
Member

zllkjc commented Feb 28, 2026

Just end the Spring Festival. I'll do a complete review of this PR next week. Thanks again for the contribution!

@zllkjc
Copy link
Copy Markdown
Member

zllkjc commented Mar 16, 2026

Thank you for your contribution to Modern.js, we are also eager to complete support for Tanstack Router.

However, since this framework is currently used directly by more than 70% of ByteDance's internal projects, we are not want introducing Tanstack packages directly into @modern-js/runtime.

After reviewing the code, I can see there are mainly three key change points, while the rest of the code is fully decoupled and very clean.

  1. In the Router CLI plugin, support for generating Tanstack entry code has been added.
  2. SSR runtime support for Tanstack.

Would it be possible to support Tanstack Router in the form of a plugin?

import { tanstackRouterPlugin } from '@modern-js/plugin-tanstack';

export default defineConfig({
  plugins: [tanstackRouterPlugin(...)]
})

  1. Generate Entry Code in Plugin and Disable default Router Plugin.

So first We should disable the default RouterPlugin in Modern.js. Currently, Modern.js determines whether to enable the React Router plugin by default based on whether the routes/ directory exists.

Maybe in tanstackRouterPlugin we can set routesDirectory to pages/ or views/ by default, then we can bypass the original behavior.

And we can listen generateCode Hooks in the plugin, and generate the code by own, instead of replace the code which generate by React Router Plugin.

If you think bypassing the routing directory is not ideal, we could also build in plugin detection — though there may be even better ways to handle this.

  1. SSR Support

We currently don't have a rich set of SSR runtime hooks, so the changes you've made in the code cannot be injected directly through a plugin at this point.

I'd like to first confirm whether SSR is a requirement in the context of Tanstack for your use case — or rather, in your project.

From my perspective, Tanstack is a client-first framework and SSR is still an experimental feature on their end. If it is necessary, we can quickly discuss what hooks are needed here and work on providing support.


Thank you again for your support of Modern.js~

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 16, 2026

Deploy Preview for modernjs-byted ready!

Name Link
🔨 Latest commit 2a3ac76
🔍 Latest deploy log https://app.netlify.com/projects/modernjs-byted/deploys/6a075c5aabcfe70008938c4b
😎 Deploy Preview https://deploy-preview-8317--modernjs-byted.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@BleedingDev
Copy link
Copy Markdown
Author

Thanks for detailed feedback. I'd love to have full powers of Modern.js with Tanstack, so SSR is key for me as well, but it can be split into multiple phases. :) In the end I'd like to have similar or better experience than Tanstack Start, but with powers of RsPack instead of Vite.

In fact I decided to take it even further and add EffectTS as alternative to Hono and do some more wild changes to Modern.js, but I keep it in my repository, where it won't polute main project as I am aware of huge usage inside ByteDance.
https://github.com/bleedingDev/ultramodern.js
I might do a detailed analysis of what might be extracted as plugin, so that it will be more clean than touching core!

@BleedingDev BleedingDev force-pushed the feat/tanstack-router-tailwind-first-class branch from 8f25fa2 to b995440 Compare March 17, 2026 06:27
@zllkjc
Copy link
Copy Markdown
Member

zllkjc commented Mar 17, 2026

so SSR is key for me as well, but it can be split into multiple phases

Yes, we can do this. We can first merge the "Hooks required for SSR runtime extension" separately, and then put Tanstack Router onto it.

I might do a detailed analysis of what might be extracted as plugin, so that it will be more clean than touching core!

We can discuss the required extension capabilities in the issue at any time. Of course, we also do not reject necessary core changes.

add EffectTS as alternative to Hono

I have a slight doubt about this. EffectTS (upper-level type system + solutions for side effects, errors, etc.) and Hono (underlying web server) should be non-conflicting capabilities. I'm not sure how to alternative.

@BleedingDev
Copy link
Copy Markdown
Author

Yes, we can do this. We can first merge the "Hooks required for SSR runtime extension" separately, and then put Tanstack Router onto it.

Let me know if I can help or if the hooks and planning is on your side. :)

We can discuss the required extension capabilities in the issue at any time. Of course, we also do not reject necessary core changes.

To be precise I did this after getting inspired by @ScriptedAlchemy, I hadn't study Modern.js in depth. I just had a goal.

I have a slight doubt about this. EffectTS (upper-level type system + solutions for side effects, errors, etc.) and Hono (underlying web server) should be non-conflicting capabilities. I'm not sure how to alternative.

Partially yes, Effect is more complex, but they also have HttpApi, that is competing with Hono directly. I have proof of concept in my repository in another branch, where I changed everything Hono based towards Effect based (including context, better type safety etc.).

@zllkjc
Copy link
Copy Markdown
Member

zllkjc commented Mar 17, 2026

Let me know if I can help or if the hooks and planning is on your side. :)

I will quickly evaluate the Hooks that need to be added based on your current code changes. If you have any new requirements, feel free to let me know.

@BleedingDev
Copy link
Copy Markdown
Author

In the future I'd like to work with RSC as well, but that would have to wait till proper implementation in Tanstack Start, so that it is close to each other, because I trust Tanner's choices in this area. So that is future area, but not mandatory now.

@BleedingDev BleedingDev force-pushed the feat/tanstack-router-tailwind-first-class branch from b995440 to 32b44a7 Compare March 18, 2026 07:12
@BleedingDev BleedingDev force-pushed the feat/tanstack-router-tailwind-first-class branch from 32b44a7 to 44b0499 Compare May 14, 2026 23:48
@BleedingDev BleedingDev force-pushed the feat/tanstack-router-tailwind-first-class branch from 44b0499 to f351380 Compare May 15, 2026 09:41
@BleedingDev BleedingDev changed the title feat: first-class TanStack Router integration + Tailwind create scaffold feat: first-class TanStack Router plugin integration May 15, 2026
@BleedingDev
Copy link
Copy Markdown
Author

Thanks for the review context. One thing I want to clarify about the current PR shape:

This PR is currently an integrated TanStack Router review branch, not the smallest possible merge slice. I kept it as one PR for now because I do not want to spam the Modern.js team with several PRs before you confirm the preferred review/merge direction.

That said, I agree the final merge path can be split if that is easier to review. The natural stacked split would be:

  1. Modern.js router / SSR extension hooks only

    • Generic route CLI ownership / generation extension points.
    • Generic SSR runtime extension points for plugin-owned routers.
    • No TanStack dependency in @modern-js/runtime.
    • This is the part that matches your earlier suggestion: first merge the hooks required for SSR runtime extension.
  2. @modern-js/plugin-tanstack basic plugin

    • Standalone plugin package.
    • TanStack route generation and runtime wiring.
    • Client/router integration tests.
  3. TanStack SSR support

    • Plugin-owned SSR snapshot / hydration behavior.
    • Loader/action SSR behavior.
    • SSR integration fixtures.
  4. Docs and examples, close to each feature

    • I would keep documentation with the PR that introduces or changes the behavior, instead of leaving all docs until one large docs-only PR at the end.

I already have the follow-up parity work implemented in my fork, and I can prepare/refine it as stacked follow-up branches if you want this split:

  • feat/tanstack-route-metadata-revalidation: route handle / shouldRevalidate parity.
  • feat/tanstack-runtime-parity: loaderFailureMode: "clientRender", unstable_reloadOnURLMismatch, and Modern runtime-level navigation blocking parity.
  • feat/tanstack-viewport-prefetch: Modern prefetch intent mapped to TanStack preload behavior.
  • feat/tanstack-rsc-data-layer: TanStack-native RSC data helpers and docs, with the public API kept under @modern-js/plugin-tanstack/runtime/rsc/*.

So my preference is:

  • Keep this PR as the integrated review branch until you tell me whether you prefer a split.
  • If you prefer a split, I can open the stacked PRs above and make each PR contain only the minimum required changes for that layer.
  • I will not add unrelated UltraModern / SuperApp / Effect work to Modern.js upstream PRs.

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