Skip to content

Point the test site's code samples at the test site - #275

Merged
jodeleeuw merged 1 commit into
testfrom
fix/env-base-url
Sep 22, 2026
Merged

jodeleeuw merged 1 commit into
testfrom
fix/env-base-url

Conversation

@jodeleeuw

Copy link
Copy Markdown
Member

Fixes #246.

Why

Both deploy workflows set NEXT_PUBLIC_BASE_URL, but nothing read it. The code samples on datapipe-test.web.app passed no base URL, so they fell through to the packages' built-in https://pipe.jspsych.org. A tester who copied one wrote data to production, against real researchers' experiments. The API reference also printed the production origin.

What changed

  • lib/base-url.js (new) reads NEXT_PUBLIC_BASE_URL, falling back to production when it is unset or blank. It is a literal process.env reference because Next.js inlines it at build time.
  • API reference: ApiPrimitives.js uses it instead of a hardcoded URL.
  • Code samples: on any non-production build, every sample passes the deployment explicitly.
    • jsPsych extension: base_url in the extension params, and as an option to saveBase64Data and getCondition.
    • datapipe-client: baseURL on saveData, createSession, saveBase64Data and getCondition.
  • Production samples are unchanged. There the packages' default is already right, so no override appears.

No package release is needed. @jspsych/extension-pipe@0.2.0 and datapipe-client already accept these options.

Testing

  • New __tests__/base-url.test.js covers the fallback, trailing slashes, and when an override is emitted.
  • extension-snippet.test.js now executes the sample with an override and checks that base_url reaches the extension.
  • next build with NEXT_PUBLIC_BASE_URL=https://datapipe-test.web.app: the prerendered API reference has no pipe.jspsych.org/api, and the docs' extension samples carry the test URL.
  • The JavaScript tabs are not prerendered, so a throwaway render checked them with the test URL. All four include baseURL and parse.
  • eslint is clean. The full emulator suite was not run.

🤖 Generated with Claude Code

Both deploy workflows set NEXT_PUBLIC_BASE_URL, but nothing read it, so
samples copied from datapipe-test.web.app fell through to the packages'
built-in pipe.jspsych.org and wrote to production. The API reference
printed the production origin too.

lib/base-url.js now reads it, with production as the fallback. The API
reference uses it, and on any non-production build every sample passes
the deployment explicitly (base_url for the extension, baseURL for
datapipe-client). Production samples are unchanged.

Fixes #246

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@jodeleeuw
jodeleeuw merged commit 843b994 into test Sep 22, 2026
1 check passed
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