Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- Preserve parentheses around multiplication, division, and modulo expressions used as exponents. https://github.com/rescript-lang/rescript/pull/8550
- Preserve multibyte characters when wrapping long source lines in compiler code frames. https://github.com/rescript-lang/rescript/pull/8520
- Fix reanalyze optional-argument diagnostics for functions passed or returned as first-class values. https://github.com/rescript-lang/rescript/pull/8321
- Prevent the developer playground from loading stale compiler and library assets after PR preview updates. https://github.com/rescript-lang/rescript/pull/8556

#### :memo: Documentation

Expand Down
23 changes: 17 additions & 6 deletions packages/dev-playground/src/CompilerApi.res
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ let isConfiguredVersion = version =>
let isLoadableVersion = version =>
version->isConfiguredVersion || version->previewVersionRoot->Option.isSome

// A PR preview URL is reused after every push, while the CDN caches its assets.
let previewCacheBust = Date.now()->Float.toString
Comment thread
cknitt marked this conversation as resolved.

let versionAssetUrl = (version, path) => {
let url = `${versionRoot(version)}/${path}`
version->isPreviewVersion ? `${url}?cacheBust=${previewCacheBust}` : url
}
Comment on lines +177 to +180

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add regression coverage for preview asset cache busting

Add an automated test covering this URL-generation behavior: a pr-123 selection should apply the same cache-busting value to compiler.js and both runtime-library scripts, while configured and local versions remain unchanged. The commit currently relies only on manual verification, so a later loader refactor could silently restore the stale-preview behavior this bug fix addresses.

AGENTS.md reference: AGENTS.md:L169-L174

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The developer playground does not currently have an automated test harness. Adding one would require introducing and wiring up new test infrastructure, which feels outside the scope of this targeted cache fix.


let selectableCompilerVersions = activeVersion =>
if activeVersion->isConfiguredVersion || !(activeVersion->previewVersionRoot->Option.isSome) {
availableCompilerVersions
Expand Down Expand Up @@ -362,16 +370,20 @@ let loadRuntimeLibraries = async version => {
switch activeLibraryVersion.contents {
| Some(activeVersion) if activeVersion === selectedVersion => ()
| _ =>
let root = versionRoot(selectedVersion)
let _ = await loadScript(`${root}/compiler-builtins/cmij.js`, ~cache=false)
let _ = await loadScript(
versionAssetUrl(selectedVersion, "compiler-builtins/cmij.js"),
~cache=false,
)

let libraries = try {
let _ = await loadScript(`${root}/@rescript/react/cmij.js`, ~cache=false)
let _ = await loadScript(
versionAssetUrl(selectedVersion, "@rescript/react/cmij.js"),
~cache=false,
)
["compiler-builtins", "@rescript/react"]
} catch {
| _ => ["compiler-builtins"]
}

loadedLibrariesByVersion->Map.set(selectedVersion, libraries)
activeLibraryVersion := Some(selectedVersion)
}
Expand All @@ -389,8 +401,7 @@ let ensureCompilerApi = async version => {
await loadRuntimeLibraries(selectedVersion)
compilerApis->getMapValueOrThrow(selectedVersion, "Compiler API was not cached")
} else {
let root = versionRoot(selectedVersion)
await loadScript(`${root}/compiler.js`)
await loadScript(versionAssetUrl(selectedVersion, "compiler.js"))
let api = switch Api.global {
| Some(api) if hasFunction(api, "make") => api
| _ => JsError.throwWithMessage("rescript_compiler global was not registered by compiler.js")
Expand Down
Loading