Skip to content

fix: support optional params in Netlify split mode - #7

Open
anurag6569201 wants to merge 1 commit into
qa/agent-sveltejs-kit/pr-07-17020/basefrom
qa/agent-sveltejs-kit/pr-07-17020/head
Open

anurag6569201 wants to merge 1 commit into
qa/agent-sveltejs-kit/pr-07-17020/basefrom
qa/agent-sveltejs-kit/pr-07-17020/head

Conversation

@anurag6569201

Copy link
Copy Markdown

closes sveltejs#9825

This maps [[optional]] segments to URLPattern's native optional named-parameter syntax (:param?).


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Netlify split-function routing for requests where optional URL parameters are omitted.
    • Improved generated function names and route matching for optional and rest parameters.
  • Tests

    • Added coverage for routes with optional parameters both present and absent.
    • Verified that generated functions include all expected route paths.

Source merge-base: 3b688deb803e77ab39c2c7adf81c5c3c168f73d7
Source head: 1a9f6b8b3d34e9eb97d49c783e82b9d1fc057245

@shipwright-agent

Copy link
Copy Markdown

⛔ Shipwright · Blocked

Recommendation: do not merge PR #7 · Tier T1
Checks: 0 total · 0 needing attention

Next step: resolve the blocking findings before merge.

Findings (3)

  • CRITICAL The function name generation uses 'parts.join('-')' where 'parts' now contains ':param1?'. · packages/adapter-netlify/index.js:163
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • CRITICAL The optional parameter detection uses a regex '/^[[.+]]$/' on 'segment.content'. · packages/adapter-netlify/index.js:152
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.
  • HIGH The variable shadowing in 'patterns.forEach((pattern) => seen.add(pattern))' reuses the name 'pattern' for the loop parameter, shadowing the outer 'const pattern'. · packages/adapter-netlify/index.js:171
    • Fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

Fireworks usage: 7,879 input · 546 output · 8,425 total tokens · $0.0021 · 12s · 0 fix iteration(s)

Open the Shipwright check for full evidence and the audit bundle. Use /shipwright rerun to verify again.

const pattern = `/${parts.join('/')}`;
const name =
FUNCTION_PREFIX + (parts.join('-').replace(/[:.]/g, '_').replace('*', '__rest') || 'index');
FUNCTION_PREFIX +

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shipwright · CRITICAL

The function name generation uses 'parts.join('-')' where 'parts' now contains ':param1?'.

Impact: The function name generation uses 'parts.join('-')' where 'parts' now contains ':param1?'. The '.replace(/[:.]/g, '_')' runs before '.replace(/?/g, '')', so the '?' is removed, but the test expects the file 'sveltekit-collection-_param1-article.mjs'. However, for a route with multiple optional params or a rest segment combined with optional params, the '?' removal can create name collisions. More critically, the 's…

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.


const patterns = [pattern, `${pattern === '/' ? '' : pattern}/__data.json`];
patterns.forEach((p) => seen.add(p));
patterns.forEach((pattern) => seen.add(pattern));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shipwright · HIGH

The variable shadowing in 'patterns.forEach((pattern) => seen.add(pattern))' reuses the name 'pattern' for the loop parameter, shadowing the outer 'const pattern'.

Impact: The variable shadowing in 'patterns.forEach((pattern) => seen.add(pattern))' reuses the name 'pattern' for the loop parameter, shadowing the outer 'const pattern'. This is confusing and error-prone; a future maintainer modifying the loop body may inadvertently reference the wrong 'pattern'. The original code used 'p' to avoid this. This change reduces clarity without functional benefit.

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

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.

1 participant