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

fix(types): exclude non serializable options from route rules #1047

Merged
merged 2 commits into from
Mar 13, 2023

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Mar 13, 2023

πŸ”— Linked issue

closes #977

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

We were wrongly typing non-supported cache options (nonserializable functions) for cache key in routeRules.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@pi0
Copy link
Member Author

pi0 commented Mar 13, 2023

cc @danielroe if you know a smarter way to auto-exclude all non-pojos feel free to change it.

@danielroe
Copy link
Member

Will push.

@pi0 pi0 merged commit 4da88f9 into main Mar 13, 2023
@pi0 pi0 deleted the fix/cache-rule-types branch March 13, 2023 14:01
@William-WFC
Copy link

William-WFC commented Aug 29, 2023

I find getKey still invalid in routeRules > cache, in nitro.config.js
here is my config

nitro: {
        devStorage: {
            'v_pc': {
                driver: 'redis',
                /* redis connector options */
                port: 6379, // Redis port
                host: 'localhost', // Redis host
                db: 0, // Defaults to 0
                maxRetriesPerRequest: 2,
            },
        },
        routeRules: {
            '/**': {
                cache: {
                    name: 'my_name',
                    swr: false,
                    maxAge: 6 * 60,
                    base: 'v_pc',
                    getKey: () => 'hhhiii',
                },
            },
        },
    },

I console.log in here (in route-rules.mjs file),

const config = useRuntimeConfig();
console.log('config.nitro.routeRules', config.nitro.routeRules)
const _routeRulesMatcher = toRouteMatcher(
  createRadixRouter({ routes: config.nitro.routeRules })
);

getKey is lost

config.nitro.routeRules {
  '/__nuxt_error': { cache: false },
  '/**': { cache: { name: 'my_name', swr: false, maxAge: 360, base: 'v_pc' } }
}

I guess this is a bug. getKey is lost In the process of delivery.

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.

routeRules cache config does not support using functions like getKey or shouldInvalidateCache
3 participants